Skip to content

Commit

Permalink
fixed a couple of calls so that it has better performance and use the…
Browse files Browse the repository at this point in the history
… internal cacheing.
  • Loading branch information
etgryphon committed Feb 19, 2011
1 parent d0f6b84 commit 2e351f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
10 changes: 6 additions & 4 deletions frameworks/linkit/mixins/node.js
Expand Up @@ -114,11 +114,13 @@ LinkIt.Node = {
Fired by an observer on the links array that gets setup in initMixin.
*/
_linksDidChange: function() {
//console.log('%@._linksDidChange()'.fmt(this));
// console.log('%@._linksDidChange()'.fmt(this));
// Call invalidate function
if (this._invalidationDelegate) {
var method = this._invalidationDelegate[this._invalidationAction];
if (method) method.apply(this._invalidationDelegate);
var func, inact, indel = this._invalidationDelegate;
if (this._invalidationDelegate ) {
inact = this._invalidationAction;
func = indel[inact];
if (func) indel.invokeLast(inact);
}
}

Expand Down
79 changes: 39 additions & 40 deletions frameworks/linkit/views/canvas.js
Expand Up @@ -66,7 +66,7 @@ LinkIt.CanvasView = SC.CollectionView.extend({

/**
*/
displayProperties: ['frame', 'links.[]'],
displayProperties: ['frame'],

// PUBLIC METHODS

Expand Down Expand Up @@ -354,43 +354,44 @@ LinkIt.CanvasView = SC.CollectionView.extend({

_updateLinks: function() {
//console.log('%@._updateLinks()'.fmt(this));
var links = [];
var nodes = this.get('content');
if (nodes) {
var numNodes = nodes.get('length');
var node, i, j, nodeLinks, key, len, link;
var startNode, endNode;

for (i = 0; i < numNodes; i++) {
node = nodes.objectAt(i);
if (node && (key = node.get('linksKey'))) {
nodeLinks = node.get(key) || [];
links = links.concat(nodeLinks);
}
}
var x, curr, links = [],
ni = this._nodeIndex || {},
nodes = this.get('content');
if (nodes) {
var numNodes = nodes.get('length');
var node, i, j, nodeLinks, key, len, link;
var startNode, endNode;
for( x in ni ){
node = ni[x];
if (node && (key = node.get('linksKey'))) {
nodeLinks = node.get(key);
links = links.concat(nodeLinks);
}
}

var linkSelection = this.get('linkSelection');
this.set('linkSelection', null);
if (linkSelection) {
var selectedID = LinkIt.genLinkID(linkSelection);
len = links.get('length');
for (i = 0; i < len; i++) {
link = links.objectAt(i);
if (LinkIt.genLinkID(link) === selectedID) {
this.set('linkSelection', link);
link.set('isSelected', YES);
break;
}
}
}
}
this.set('links', links);
var linkSelection = this.get('linkSelection');
this.set('linkSelection', null);
if (linkSelection) {
var selectedID = LinkIt.genLinkID(linkSelection);
len = links.get('length');
for (i = 0; i < len; i++) {
link = links.objectAt(i);
if (LinkIt.genLinkID(link) === selectedID) {
this.set('linkSelection', link);
link.set('isSelected', YES);
break;
}
}
}
}
this._links = links;
this.updateCanvas();
},

/**
*/
_drawLinks: function(context) {
var links = this.get('links');
var links = this._links;
var numLinks = links.get('length');
var link, points, i, linkID;
for (i = 0; i < numLinks; i++) {
Expand Down Expand Up @@ -440,7 +441,7 @@ LinkIt.CanvasView = SC.CollectionView.extend({
*/
_selectLink: function(pt) {
//console.log('%@._selectLink()'.fmt(this));
var links = this.get('links') || [];
var links = this._links || [];
var len = links.get('length');
var link, dist, i;

Expand Down Expand Up @@ -494,18 +495,16 @@ LinkIt.CanvasView = SC.CollectionView.extend({
var nodes = this.get('content');
var numNodes = 0;
var node, nodeID;

this.set('_nodeIndex', {});

this._nodeIndex = this._nodeIndex || {};
if (nodes) {
numNodes = nodes.get('length');

for (var i = 0; i < numNodes; i++) {
node = nodes.objectAt(i);
node.registerInvalidationDelegate(this, 'linksDidChange');

nodeID = SC.guidFor(node);
this._nodeIndex[nodeID] = { node: node };
if (SC.none(this._nodeIndex[nodeID])){
node.registerInvalidationDelegate(this, 'linksDidChange');
this._nodeIndex[nodeID] = node;
}
}
}

Expand Down

0 comments on commit 2e351f9

Please sign in to comment.