Skip to content

Commit 1474fd2

Browse files
committed
Merge pull request #1 from istr/master
fixed typo recrusive; actually use global options
2 parents daf2701 + d33ef4b commit 1474fd2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

knockout.viewmodel.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
return obj === null || obj === undefined || obj.constructor === String || obj.constructor === Number || obj.constructor === Boolean || obj instanceof Date;
7575
}
7676

77-
function recrusiveFrom(modelObj, settings, context, pathSettings) {
77+
function recursiveFrom(modelObj, settings, context, pathSettings) {
7878
var temp, result, p, length, idName, newContext, customPathSettings, extend, optionProcessed,
7979
childPathSettings, childObj;
8080
pathSettings = pathSettings || getPathSettings(settings, context);
@@ -115,7 +115,7 @@
115115
result = [];
116116

117117
for (p = 0, length = modelObj.length; p < length; p++) {
118-
result[p] = recrusiveFrom(modelObj[p], settings, {
118+
result[p] = recursiveFrom(modelObj[p], settings, {
119119
name: "[i]", parent: context.name + "[i]", full: context.full + "[i]", parentIsArray: true
120120
});
121121
}
@@ -134,20 +134,20 @@
134134
//wrap array methods for adding and removing items in functions that
135135
//close over settings and context allowing the objects and their children to be correctly mapped.
136136
result.pushFromModel = function (item) {
137-
item = recrusiveFrom(item, settings, newContext);
137+
item = recursiveFrom(item, settings, newContext);
138138
result.push(item);
139139
};
140140
result.unshiftFromModel = function (item) {
141-
item = recrusiveFrom(item, settings, newContext);
141+
item = recursiveFrom(item, settings, newContext);
142142
result.unshift(item);
143143
};
144144
result.popToModel = function (item) {
145145
item = result.pop();
146-
return recrusiveTo(item, newContext);
146+
return recursiveTo(item, newContext);
147147
};
148148
result.shiftToModel = function (item) {
149149
item = result.shift();
150-
return recrusiveTo(item, newContext);
150+
return recursiveTo(item, newContext);
151151
};
152152
}
153153

@@ -176,7 +176,7 @@
176176
}
177177
}
178178
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
180180

181181
if (temp !== badResult) {//properties that couldn't be mapped return badResult
182182
result[p] = temp;
@@ -205,7 +205,7 @@
205205
return result;
206206
}
207207

208-
function recrusiveTo(viewModelObj, context) {
208+
function recursiveTo(viewModelObj, context) {
209209
var result, p, length, temp, unwrapped = unwrap(viewModelObj), child, recursiveResult,
210210
wasWrapped = (viewModelObj !== unwrapped);//this works because unwrap observable calls isObservable and returns the object unchanged if not observable
211211

@@ -226,7 +226,7 @@
226226
else if (unwrapped instanceof Array) {//create new array to return and add unwrapped values to it
227227
result = [];
228228
for (p = 0, length = unwrapped.length; p < length; p++) {
229-
result[p] = recrusiveTo(unwrapped[p], {
229+
result[p] = recursiveTo(unwrapped[p], {
230230
name: "[i]", parent: context.name + "[i]", full: context.full + "[i]"
231231
});
232232
}
@@ -242,7 +242,7 @@
242242
child = unwrapped[p];
243243
if (!ko.isComputed(child) && !((temp = unwrap(child)) && temp.constructor === Function)) {
244244

245-
recursiveResult = recrusiveTo(child, {
245+
recursiveResult = recursiveTo(child, {
246246
name: p,
247247
parent: (context.name === "[i]" ? context.parent : context.name) + "." + p,
248248
full: context.full + "." + p
@@ -358,7 +358,7 @@
358358
child(unwrap(tempChild));
359359
}
360360
//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
362362
}
363363
else {
364364
unwrapped[q] = child.___$mapCustom(modelObj[p], child);
@@ -477,13 +477,15 @@
477477
logging: false
478478
},
479479
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];
480482
var settings = getPathSettingsDictionary(options);
481483
initInternals(this.options, "Mapping From Model");
482-
return recrusiveFrom(model, settings, rootContext);
484+
return recursiveFrom(model, settings, rootContext);
483485
},
484486
toModel: function fnToModel(viewmodel) {
485487
initInternals(this.options, "Mapping To Model");
486-
return recrusiveTo(viewmodel, rootContext);
488+
return recursiveTo(viewmodel, rootContext);
487489
},
488490
updateFromModel: function fnUpdateFromModel(viewmodel, model, makeNoncontiguousObjectUpdates) {
489491
var noncontiguousObjectUpdateCount = makeNoncontiguousObjectUpdates ? ko.observable(0) : undefined;

0 commit comments

Comments
 (0)