aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/core/extras/object.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/core/extras/object.js')
-rw-r--r--node_modules/montage/core/extras/object.js41
1 files changed, 13 insertions, 28 deletions
diff --git a/node_modules/montage/core/extras/object.js b/node_modules/montage/core/extras/object.js
index 0281240f..d20b57fa 100644
--- a/node_modules/montage/core/extras/object.js
+++ b/node_modules/montage/core/extras/object.js
@@ -113,42 +113,27 @@ Object.defineProperty(Object.prototype, "setProperty", {
113 // TODO clean up some of the duplicated code here 113 // TODO clean up some of the duplicated code here
114 114
115 if (lastObjectAtPath && Array.isArray(lastObjectAtPath)) { 115 if (lastObjectAtPath && Array.isArray(lastObjectAtPath)) {
116 if (lastObjectAtPath !== value) { 116
117 // if the value does not match the object described by this propertyPath; set it as the new value 117 if (Array.isArray(setObject)) {
118 118 // If the setObject is an array itself; splice (typically called by set) to trigger bindings, do it here to save time
119 if (Array.isArray(setObject)) { 119 propertyToSetOnArray = parseInt(aPropertyPath, 10);
120 // If the setObject is an array itself; splice (typically called by set) to trigger bindings, do it here to save time 120 if (!isNaN(propertyToSetOnArray)) {
121 propertyToSetOnArray = parseInt(aPropertyPath, 10); 121 if (setObject.length < propertyToSetOnArray) {
122 if (!isNaN(propertyToSetOnArray)) { 122 // TODO while I could set the value here I'm setting null and letting the splice,
123 if (setObject.length < propertyToSetOnArray) { 123 // which we need to do anyway to trigger bindings, do the actual setting
124 // TODO while I could set the value here I'm setting null and letting the splice, 124 setObject[propertyToSetOnArray] = null;
125 // which we need to do anyway to trigger bindings, do the actual setting
126 setObject[propertyToSetOnArray] = null;
127 }
128
129 setObject.splice(propertyToSetOnArray, 1, value);
130
131 } else {
132 setObject[aPropertyPath] = value;
133 } 125 }
134 126
127 setObject.splice(propertyToSetOnArray, 1, value);
128
135 } else { 129 } else {
136 setObject[aPropertyPath] = value; 130 setObject[aPropertyPath] = value;
137 } 131 }
138 132
139 } else { 133 } else {
140 // Otherwise, they are the same object, a mutation event probably happened 134 setObject[aPropertyPath] = value;
141
142 // If the object at the property we're "setting" is itself an array, see if there was an event passed along
143 // as part of a change and whether we need to call the setObject's changeProperty method
144 var changeEvent = this.setProperty.changeEvent, modify;
145
146 // For these mutation/addition/removal events, use the 'modify' attribute of this property's descriptor
147 if (changeEvent && (changeEvent.currentTarget.getProperty(changeEvent.currentPropertyPath) === lastObjectAtPath) &&
148 (modify = M.Montage.getPropertyAttribute(setObject, aPropertyPath, MODIFY))) {
149 modify.call(setObject, changeEvent.type, changeEvent.newValue, changeEvent.prevValue);
150 }
151 } 135 }
136
152 } else if (Array.isArray(setObject)) { 137 } else if (Array.isArray(setObject)) {
153 // If the setObject is an array itself; splice (typically called by set) to trigger bindings, do it here to save time 138 // If the setObject is an array itself; splice (typically called by set) to trigger bindings, do it here to save time
154 propertyToSetOnArray = parseInt(aPropertyPath, 10); 139 propertyToSetOnArray = parseInt(aPropertyPath, 10);