r101034 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101033‎ | r101034 | r101035 >
Date:20:18, 27 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Fixed a bug in es.ModelNode where attach did not propagate changes in root downstream
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js
@@ -23,6 +23,10 @@
2424 node.emit( 'update' );
2525 };
2626
 27+ // Properties
 28+ node.parent = null;
 29+ node.root = node;
 30+
2731 // Children
2832 if ( es.isArray( children ) ) {
2933 for ( var i = 0; i < children.length; i++ ) {
@@ -30,10 +34,6 @@
3135 }
3236 }
3337
34 - // Properties
35 - node.parent = undefined;
36 - node.root = node;
37 -
3838 return node;
3939 };
4040
@@ -216,7 +216,7 @@
217217 es.ModelNode.prototype.attach = function( parent ) {
218218 this.emit( 'beforeAttach', parent );
219219 this.parent = parent;
220 - this.root = parent.getRoot();
 220+ this.setRoot( parent.getRoot() );
221221 this.emit( 'afterAttach', parent );
222222 };
223223
@@ -228,12 +228,37 @@
229229 */
230230 es.ModelNode.prototype.detach = function() {
231231 this.emit( 'beforeDetach' );
232 - this.parent = undefined;
233 - this.root = this;
 232+ this.parent = null;
 233+ this.clearRoot();
234234 this.emit( 'afterDetach' );
235235 };
236236
237237 /**
 238+ * Sets the root node to this and all of it's children.
 239+ *
 240+ * @method
 241+ * @param {es.ModelNode} root Node to use as root
 242+ */
 243+es.ModelNode.prototype.setRoot = function( root ) {
 244+ this.root = root;
 245+ for ( var i = 0; i < this.length; i++ ) {
 246+ this[i].setRoot( root );
 247+ }
 248+};
 249+
 250+/**
 251+ * Clears the root node from this and all of it's children.
 252+ *
 253+ * @method
 254+ */
 255+es.ModelNode.prototype.clearRoot = function() {
 256+ this.root = null;
 257+ for ( var i = 0; i < this.length; i++ ) {
 258+ this[i].clearRoot();
 259+ }
 260+};
 261+
 262+/**
238263 * Creates a view for this node.
239264 *
240265 * @method

Status & tagging log