Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed

  • Loading branch information...
commit 9eebd673ea70c51c077b56b32017f507a6cf2005 1 parent 3fc42b9
@leshy authored
Showing with 46 additions and 22 deletions.
  1. +46 −22 app.js
View
68 app.js
@@ -83,7 +83,7 @@ var GenericGraphNode = Backbone.Model.extend({
return f(args)
}
- _.map(['add','remove','has'], function(fname) {
+ _.map(['get', 'add', 'remove', 'has'], function(fname) {
self.fname = decorate(plugfundecorator,self.fname)
})
@@ -101,52 +101,76 @@ var GenericGraphNode = Backbone.Model.extend({
this[ plugplural ] = new Backbone.Collection()
- this[ 'add' + plugsingular ] = decorate(decorators.multiArg,function(obj) { return self.add.call(self,plugplural,obj) })
- this[ 'del' + plugsingular ] = decorate(decorators.multiArg,function(obj) { return self.remove.call(self,plugplural,obj) })
- this[ 'has' + plugsingular ] = function(obj) { return self.has.call(self,plugplural,obj) }
- this[ 'get' + plugplural ] = function(obj) { return self[plugplural].models }
+ this[ 'add' + plugsingular ] = decorate(decorators.multiArg,function(obj) { return self.plugadd.call(self,plugplural,obj) })
+ this[ 'del' + plugsingular ] = decorate(decorators.multiArg,function(obj) { return self.plugremove.call(self,plugplural,obj) })
+ this[ 'has' + plugsingular ] = function(obj) { return self.plughas.call(self,plugplural,obj) }
+ this[ 'get' + plugsingular ] = function() { return _.first(self.plugget.call(self,plugplural)) }
+ this[ 'get' + plugplural ] = function() { return self.plugget.call(self,plugplural) }
+
+ },
+
+ plugget: function(plug) {
+ return this[plug].models
},
- add: function(plug,obj) {
- this[plug].add(obj)
+ plugadd: function(plug,obj) {
+ //console.log(this.get('name'), 'add', plug,obj.get('name'))
+ if (!this.plughas(plug,obj)) { this[plug].add(obj) }
},
- remove: function(plug,obj) {
+ plugremove: function(plug,obj) {
this[plug].remove(obj)
},
- has: function(plug, obj) {
+ plughas: function(plug, obj) {
return (this[plug].indexOf(obj) != -1)
},
+
})
// GraphNode specializes GenericGraphNode by adding 'children' and 'parents' plugs
var GraphNode = GenericGraphNode.extend4000({
initialize: function() {
+ var self = this;
+
this.addplug('parents','parent')
this.addplug('children','child')
- }
-})
-
-
+
+ this.parents.on('add',function(obj) {
+ obj.addchild(self)
+ })
-var a = new GraphNode()
-var b = new GraphNode()
-console.log(a.parents)
+ this.children.on('add',function(obj) {
+ obj.addparent(self)
+ })
-var c = new Backbone.Model()
+
+ /*
+ this.on('addparent', function(model,obj) {
+ obj.addchild(self)
+ })
-a.addparent(c)
+ this.on('addchild', function(model,obj) {
+ obj.addparent(self)
+ })
+ */
+
+ }
+})
-console.log(a.hasparent(c))
-console.log(b.hasparent(c))
+var CommNode = GraphNode.extend4000({
+ MsgIn: function(message) {
+ return _.flatten(this.children.map(function(child) { return child.MsgIn(message) }))
+ },
+ MsgOut: function(message) {
+ return _.flatten(this.parents.map(function(parent) { parent.MsgOut(message) }))
+ }
+})
-//console.log(a.parents)
-console.log(_.keys(a.plugs))

0 comments on commit 9eebd67

Please sign in to comment.
Something went wrong with that request. Please try again.