This will allow for improving accessors to be smarter about making
decision whether or not to return node via path. This is necessary
to fix a bug caused by invalidated paths.
return;
}
_.keys(obj).forEach(function(key) {
return;
}
_.keys(obj).forEach(function(key) {
- var value = obj[key],
- path;
if(value) {
if(value.nodeType) {
if(value) {
if(value.nodeType) {
- path = value.getPath();
- Object.defineProperty(obj, key, {
- get: function() {
- if(transformation.hasRun && path) {
- return transformation.document.getNodeByPath(path);
- } else {
- return value;
- }
- }
- });
+ transformation.wrapNodeProperty(obj, key);
} else if(_.isObject(value)) {
patchObject(value, depth+1);
}
} else if(_.isObject(value)) {
patchObject(value, depth+1);
}
};
this.args.forEach(function(arg, idx, args) {
};
this.args.forEach(function(arg, idx, args) {
if(arg) {
if(arg.nodeType) { // ~
if(arg) {
if(arg.nodeType) { // ~
- path = arg.getPath();
- Object.defineProperty(args, idx, {
- get: function() {
- if(transformation.hasRun && path) {
- return transformation.document.getNodeByPath(path);
- } else {
- return arg;
- }
- }
- });
+ transformation.wrapNodeProperty(args, idx);
} else if(_.isObject(arg)) {
patchObject(arg);
}
} else if(_.isObject(arg)) {
patchObject(arg);
}
},
getChangeRoot: desc.getChangeRoot || function() {
return this.document.root;
},
getChangeRoot: desc.getChangeRoot || function() {
return this.document.root;
+ },
+ wrapNodeProperty: function(object, propName, value) {
+ var transformation = this,
+ path;
+
+ value = value || object[propName];
+ if(value && value.nodeType) {
+ path = value.getPath();
+ Object.defineProperty(object, propName, {
+ get: function() {
+ if(transformation.hasRun && path) {
+ return transformation.document.getNodeByPath(path);
+ } else {
+ return value;
+ }
+ }
+ });
+ }
if(document === object) {
this.context = document;
} else {
if(document === object) {
this.context = document;
} else {
- var contextPath = object.getPath(),
- transformation = this;
- Object.defineProperty(this, 'context', {
- get: function() {
- if(transformation.hasRun) {
- return transformation.document.getNodeByPath(contextPath);
- } else {
- return object;
- }
- }
- });
+ this.wrapNodeProperty(this, 'context', object);
}
};
ContextTransformation.prototype = Object.create(GenericTransformation.prototype);
}
};
ContextTransformation.prototype = Object.create(GenericTransformation.prototype);