|
74 | 74 | return obj === null || obj === undefined || obj.constructor === String || obj.constructor === Number || obj.constructor === Boolean || obj instanceof Date; |
75 | 75 | } |
76 | 76 |
|
77 | | - function recrusiveFrom(modelObj, settings, context, pathSettings) { |
| 77 | + function recursiveFrom(modelObj, settings, context, pathSettings) { |
78 | 78 | var temp, result, p, length, idName, newContext, customPathSettings, extend, optionProcessed, |
79 | 79 | childPathSettings, childObj; |
80 | 80 | pathSettings = pathSettings || getPathSettings(settings, context); |
|
115 | 115 | result = []; |
116 | 116 |
|
117 | 117 | for (p = 0, length = modelObj.length; p < length; p++) { |
118 | | - result[p] = recrusiveFrom(modelObj[p], settings, { |
| 118 | + result[p] = recursiveFrom(modelObj[p], settings, { |
119 | 119 | name: "[i]", parent: context.name + "[i]", full: context.full + "[i]", parentIsArray: true |
120 | 120 | }); |
121 | 121 | } |
|
134 | 134 | //wrap array methods for adding and removing items in functions that |
135 | 135 | //close over settings and context allowing the objects and their children to be correctly mapped. |
136 | 136 | result.pushFromModel = function (item) { |
137 | | - item = recrusiveFrom(item, settings, newContext); |
| 137 | + item = recursiveFrom(item, settings, newContext); |
138 | 138 | result.push(item); |
139 | 139 | }; |
140 | 140 | result.unshiftFromModel = function (item) { |
141 | | - item = recrusiveFrom(item, settings, newContext); |
| 141 | + item = recursiveFrom(item, settings, newContext); |
142 | 142 | result.unshift(item); |
143 | 143 | }; |
144 | 144 | result.popToModel = function (item) { |
145 | 145 | item = result.pop(); |
146 | | - return recrusiveTo(item, newContext); |
| 146 | + return recursiveTo(item, newContext); |
147 | 147 | }; |
148 | 148 | result.shiftToModel = function (item) { |
149 | 149 | item = result.shift(); |
150 | | - return recrusiveTo(item, newContext); |
| 150 | + return recursiveTo(item, newContext); |
151 | 151 | }; |
152 | 152 | } |
153 | 153 |
|
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | else { |
179 | | - temp = recrusiveFrom(childObj, settings, newContext, childPathSettings);//call recursive from on each child property |
| 179 | + temp = recursiveFrom(childObj, settings, newContext, childPathSettings);//call recursive from on each child property |
180 | 180 |
|
181 | 181 | if (temp !== badResult) {//properties that couldn't be mapped return badResult |
182 | 182 | result[p] = temp; |
|
205 | 205 | return result; |
206 | 206 | } |
207 | 207 |
|
208 | | - function recrusiveTo(viewModelObj, context) { |
| 208 | + function recursiveTo(viewModelObj, context) { |
209 | 209 | var result, p, length, temp, unwrapped = unwrap(viewModelObj), child, recursiveResult, |
210 | 210 | wasWrapped = (viewModelObj !== unwrapped);//this works because unwrap observable calls isObservable and returns the object unchanged if not observable |
211 | 211 |
|
|
226 | 226 | else if (unwrapped instanceof Array) {//create new array to return and add unwrapped values to it |
227 | 227 | result = []; |
228 | 228 | for (p = 0, length = unwrapped.length; p < length; p++) { |
229 | | - result[p] = recrusiveTo(unwrapped[p], { |
| 229 | + result[p] = recursiveTo(unwrapped[p], { |
230 | 230 | name: "[i]", parent: context.name + "[i]", full: context.full + "[i]" |
231 | 231 | }); |
232 | 232 | } |
|
242 | 242 | child = unwrapped[p]; |
243 | 243 | if (!ko.isComputed(child) && !((temp = unwrap(child)) && temp.constructor === Function)) { |
244 | 244 |
|
245 | | - recursiveResult = recrusiveTo(child, { |
| 245 | + recursiveResult = recursiveTo(child, { |
246 | 246 | name: p, |
247 | 247 | parent: (context.name === "[i]" ? context.parent : context.name) + "." + p, |
248 | 248 | full: context.full + "." + p |
|
358 | 358 | child(unwrap(tempChild)); |
359 | 359 | } |
360 | 360 | //else custom mapping returned previous observable; |
361 | | - //if it's smart enough to do that, assume it updated it correctly |
| 361 | + //if it's smart enough to do that, assume it updated it correctly |
362 | 362 | } |
363 | 363 | else { |
364 | 364 | unwrapped[q] = child.___$mapCustom(modelObj[p], child); |
|
477 | 477 | logging: false |
478 | 478 | }, |
479 | 479 | fromModel: function fnFromModel(model, options) { |
| 480 | + // merge in global options |
| 481 | + if (options) for (opt in this.options) if (options[opt]) this.options[opt] = options[opt]; |
480 | 482 | var settings = getPathSettingsDictionary(options); |
481 | 483 | initInternals(this.options, "Mapping From Model"); |
482 | | - return recrusiveFrom(model, settings, rootContext); |
| 484 | + return recursiveFrom(model, settings, rootContext); |
483 | 485 | }, |
484 | 486 | toModel: function fnToModel(viewmodel) { |
485 | 487 | initInternals(this.options, "Mapping To Model"); |
486 | | - return recrusiveTo(viewmodel, rootContext); |
| 488 | + return recursiveTo(viewmodel, rootContext); |
487 | 489 | }, |
488 | 490 | updateFromModel: function fnUpdateFromModel(viewmodel, model, makeNoncontiguousObjectUpdates) { |
489 | 491 | var noncontiguousObjectUpdateCount = makeNoncontiguousObjectUpdates ? ko.observable(0) : undefined; |
|
0 commit comments