Skip to content

Commit be2191e

Browse files
committed
fix typos, set global options
1 parent daf2701 commit be2191e

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

knockout.viewmodel.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/*ko.viewmodel.js - version 2.0.3
1+
/*ko.viewmodel.js - version 2.0.3
22
* Copyright 2013, Dave Herren http://coderenaissance.github.com/knockout.viewmodel/
33
* License: MIT (http://www.opensource.org/licenses/mit-license.php)*/
44
/*jshint eqnull:true, boss:true, loopfunc:true, evil:true, laxbreak:true, undef:true, unused:true, browser:true, immed:true, devel:true, sub: true, maxerr:50 */
55
/*global ko:false */
66

77
(function () {
88
//Module declarations. For increased compression with simple settings on the closure compiler,
9-
//the ko functions are stored in variables. These variable names will be shortened by the compiler,
9+
//the ko functions are stored in variables. These variable names will be shortened by the compiler,
1010
//whereas references to ko would not be. There is also a performance savings from this.
1111
var unwrap = ko.utils.unwrapObservable,
1212
isObservable = ko.isObservable,
@@ -70,18 +70,18 @@
7070

7171
//while dates aren't part of the JSON spec it doesn't hurt to support them as it's not unreasonable to think they might be added to the model manually.
7272
//undefined is also not part of the spec, but it's currently be supported to be more in line with ko.mapping and probably doesn't hurt.
73-
function isPrimativeOrDate(obj) {
73+
function isPrimitiveOrDate(obj) {
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);
8181

8282
if (customPathSettings = pathSettings.custom) {
8383
optionProcessed = true;
84-
//custom can either be specified as a single map function or as an
84+
//custom can either be specified as a single map function or as an
8585
//object with map and unmap properties
8686
if (typeof customPathSettings === "function") {
8787
result = customPathSettings(modelObj);
@@ -107,15 +107,15 @@
107107
optionProcessed = true;
108108
return badResult;
109109
}
110-
else if (isPrimativeOrDate(modelObj)) {
111-
//primative and date children of arrays aren't mapped... all others are
110+
else if (isPrimitiveOrDate(modelObj)) {
111+
//primitive and date children of arrays aren't mapped... all others are
112112
result = context.parentIsArray ? modelObj : makeObservable(modelObj);
113113
}
114114
else if (modelObj instanceof Array) {
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

@@ -161,10 +161,10 @@
161161
full: context.full + "." + p
162162
};
163163
childObj = modelObj[p];
164-
childPathSettings = isPrimativeOrDate(childObj) ? getPathSettings(settings, newContext) : undefined;
164+
childPathSettings = isPrimitiveOrDate(childObj) ? getPathSettings(settings, newContext) : undefined;
165165

166166
if (childPathSettings && childPathSettings.custom) {//primativish value w/ custom maping
167-
//since primative children cannot store their own custom functions, handle processing here and store them in the parent
167+
//since primitive children cannot store their own custom functions, handle processing here and store them in the parent
168168
result.___$customChildren = result.___$customChildren || {};
169169
result.___$customChildren[p] = childPathSettings.custom;
170170

@@ -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

@@ -219,14 +219,14 @@
219219
else if (viewModelObj && viewModelObj.___$unmapCustom) {//Defer to customUnmapping where specified
220220
result = viewModelObj.___$unmapCustom(viewModelObj);
221221
}
222-
else if ((wasWrapped && isPrimativeOrDate(unwrapped)) || isNullOrUndefined(unwrapped)) {
222+
else if ((wasWrapped && isPrimitiveOrDate(unwrapped)) || isNullOrUndefined(unwrapped)) {
223223
//return null, undefined, values, and wrapped primativish values as is
224224
result = unwrapped;
225225
}
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
@@ -271,7 +271,7 @@
271271
return result;
272272
}
273273

274-
function recursiveUpdate(modelObj, viewModelObj, context, parentObj, noncontiguousObjectUpdateCount) {
274+
function recursiveUpdate(modelObj, viewModelObj, context, parentObj, nonContiguousObjectUpdateCount) {
275275
var p, q, foundModels, foundViewmodels, modelId, viewmodelId, idName, length, unwrapped = unwrap(viewModelObj),
276276
wasWrapped = (viewModelObj !== unwrapped), child, map, tempArray, childTemp, childMap, unwrappedChild, tempChild;
277277

@@ -280,7 +280,7 @@
280280
}
281281

282282
if (wasWrapped && (isNullOrUndefined(unwrapped) ^ isNullOrUndefined(modelObj))) {
283-
//if you have an observable to update and either the new or old value is
283+
//if you have an observable to update and either the new or old value is
284284
//null or undefined then update the observable
285285
viewModelObj(modelObj);
286286
}
@@ -294,7 +294,7 @@
294294
else {
295295
child = unwrapped[p];
296296

297-
if (!wasWrapped && unwrapped.hasOwnProperty(p) && (isPrimativeOrDate(child) || (child && child.constructor === Array))) {
297+
if (!wasWrapped && unwrapped.hasOwnProperty(p) && (isPrimitiveOrDate(child) || (child && child.constructor === Array))) {
298298
unwrapped[p] = modelObj[p];
299299
}
300300
else if (child && typeof child.___$mapCustom === "function") {
@@ -314,18 +314,18 @@
314314
unwrapped[p] = modelObj[p];
315315
}
316316
else {//Recursive update everything else
317-
if (!!noncontiguousObjectUpdateCount) {
317+
if (!!nonContiguousObjectUpdateCount) {
318318
var fnRecursivePropertyObjectUpdate = (function (modelObj, viewModelObj, p) {
319319
return function () {//keep in sync with else below
320320
recursiveUpdate(modelObj[p], unwrapped[p], {
321321
name: p,
322322
parent: (context.name === "[i]" ? context.parent : context.name) + "." + p,
323323
full: context.full + "." + p
324-
}, unwrapped, noncontiguousObjectUpdateCount);
325-
noncontiguousObjectUpdateCount(noncontiguousObjectUpdateCount() - 1);
324+
}, unwrapped, nonContiguousObjectUpdateCount);
325+
nonContiguousObjectUpdateCount(nonContiguousObjectUpdateCount() - 1);
326326
};
327327
}(modelObj, viewModelObj, p));
328-
noncontiguousObjectUpdateCount(noncontiguousObjectUpdateCount() + 1);
328+
nonContiguousObjectUpdateCount(nonContiguousObjectUpdateCount() + 1);
329329
setTimeout(fnRecursivePropertyObjectUpdate, 0);
330330
}
331331
else {//keep in sync with if above
@@ -358,25 +358,25 @@
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);
365365
}
366366
}
367367
else {
368-
369-
if (!!noncontiguousObjectUpdateCount) {//keep in sync with else block below
368+
369+
if (!!nonContiguousObjectUpdateCount) {//keep in sync with else block below
370370
var fnRecursiveArrayChildObjectUpdate = (function (modelObj, viewModelObj, p, q) {
371371
return function () {
372372
recursiveUpdate(modelObj[p], unwrapped[q], {
373373
name: "[i]", parent: context.name + "[i]", full: context.full + "[i]"
374-
}, undefined, noncontiguousObjectUpdateCount);
374+
}, undefined, nonContiguousObjectUpdateCount);
375375

376-
noncontiguousObjectUpdateCount(noncontiguousObjectUpdateCount() - 1);
376+
nonContiguousObjectUpdateCount(nonContiguousObjectUpdateCount() - 1);
377377
};
378378
}(modelObj, viewModelObj, p, q));
379-
noncontiguousObjectUpdateCount(noncontiguousObjectUpdateCount() + 1);
379+
nonContiguousObjectUpdateCount(nonContiguousObjectUpdateCount() + 1);
380380
setTimeout(fnRecursiveArrayChildObjectUpdate, 0);
381381
}
382382
else {//keep in sync with if block above
@@ -423,13 +423,13 @@
423423
viewModelObj(modelObj);
424424
}
425425

426-
if (context.name === "{root}" && !!noncontiguousObjectUpdateCount) {
426+
if (context.name === "{root}" && !!nonContiguousObjectUpdateCount) {
427427
return {
428428
onComplete:function (fnOnComplete) {
429429
if(fnOnComplete && typeof fnOnComplete == "function"){
430-
if (!!noncontiguousObjectUpdateCount) {
430+
if (!!nonContiguousObjectUpdateCount) {
431431
ko.computed(function () {
432-
if (fnOnComplete && noncontiguousObjectUpdateCount() === 0) {
432+
if (fnOnComplete && nonContiguousObjectUpdateCount() === 0) {
433433
fnOnComplete();
434434
fnOnComplete = undefined;
435435
}
@@ -479,16 +479,16 @@
479479
fromModel: function fnFromModel(model, options) {
480480
var settings = getPathSettingsDictionary(options);
481481
initInternals(this.options, "Mapping From Model");
482-
return recrusiveFrom(model, settings, rootContext);
482+
return recursiveFrom(model, settings, rootContext);
483483
},
484484
toModel: function fnToModel(viewmodel) {
485485
initInternals(this.options, "Mapping To Model");
486-
return recrusiveTo(viewmodel, rootContext);
486+
return recursiveTo(viewmodel, rootContext);
487487
},
488-
updateFromModel: function fnUpdateFromModel(viewmodel, model, makeNoncontiguousObjectUpdates) {
489-
var noncontiguousObjectUpdateCount = makeNoncontiguousObjectUpdates ? ko.observable(0) : undefined;
488+
updateFromModel: function fnUpdateFromModel(viewmodel, model, makeNonContiguousObjectUpdates) {
489+
var nonContiguousObjectUpdateCount = makeNonContiguousObjectUpdates ? ko.observable(0) : undefined;
490490
initInternals(this.options, "Update From Model");
491-
return recursiveUpdate(model, viewmodel, rootContext, undefined, noncontiguousObjectUpdateCount);
491+
return recursiveUpdate(model, viewmodel, rootContext, undefined, nonContiguousObjectUpdateCount);
492492
}
493493
};
494494
}());

0 commit comments

Comments
 (0)