Created
October 13, 2012 19:11
-
-
Save endash/3885801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Node = Ember.extend({ | |
datasource: null, | |
links: Ember.computed(function () { | |
var ds = this.get('datasource'); | |
if (ds) return ds.linksForNode(this.get('id)); | |
return []; | |
}).property() | |
}); | |
var Link = Ember.extend({}); | |
var node1 = Node.create({id: 1, name: "node 1"}); | |
var node2 = Node.create({id: 2, name: "node 2"}); | |
var node3 = Node.create({id: 3, name: "node 3"}); | |
var link1 = Link.create({left_node: 1, right_node: 2}); | |
var link2 = Link.create({left_node: 1, right_node: 3}); | |
var datasource = Ember.Object.create({ | |
nodes: [node1, node2, node3], | |
links: [link1, link2], | |
linksForNode: function (node_id) { | |
var links = this.get('links', function (item) { | |
return item.get('left_node') == node_id || item.get('right_node') == node_id | |
}); | |
return links; | |
} | |
}); | |
node1.set('datasource', datasource); | |
node1.get('links') => [link1, link2]; | |
node2.set('datasource', datasource); | |
node2.get('links') => [link1]; | |
node3.set('datasource', datasource); | |
node3.get('links') => [link2]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment