Skip to content

Commit 70a5e10

Browse files
committed
preparing 1.4.0-beta2 release
1 parent 85a6925 commit 70a5e10

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

dist/ko-reactor.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! ko-reactor v1.4.0-beta
1+
/*! ko-reactor v1.4.0-beta2
22
* The MIT License (MIT)
33
* Copyright (c) 2017 Ziad Jeeroburkhan */
44
// Deep observer plugin for Knockout http://knockoutjs.com/
@@ -39,6 +39,8 @@ ko.subscribable.fn['watch'] = function (targetOrCallback, options, evaluatorCall
3939
/// { tagFields: true } -> Add the property '_fieldName' under each property for textual identification.<br/>
4040
/// { tagFields: 'parentsOnly' } -> Same as above except that it is limited to parent properties only.<br/>
4141
/// { oldValues: 3 } -> Keep the last three values for each subscribable under the property 'oldValues'.<br/>
42+
/// { synchWatch: true } -> Use setTimeout to start watching new objects
43+
/// { splitArrayChanges: false } -> receive a single notification for array changes as an array of "items" instead of multiple notifications
4244
/// { seal: true } -> Prevent any subsequent watcher from watching the target again.<br/>
4345
/// { unloop: true } -> Avoid circular paths through the use of a breadcrumb property '_watcher' set at each node level.<br/>
4446
/// </param>
@@ -244,15 +246,28 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {
244246
if (isArray) {
245247
// Child is an observable array. Watch all changes within it.
246248
child.subscribe(function (changes) {
247-
ko.utils.arrayForEach(changes, function (item) {
248-
var returnValue = evaluatorCallback.call(context, parents, child, item);
249+
var returnValue;
250+
if (options.splitArrayChanges === false) {
251+
returnValue = evaluatorCallback.call(context, parents, child, changes);
249252
if (returnValue !== undefined)
250253
context(returnValue);
254+
}
255+
ko.utils.arrayForEach(changes, function (item) {
256+
if (options.splitArrayChanges !== false) {
257+
var returnValue = evaluatorCallback.call(context, parents, child, item);
258+
if (returnValue !== undefined)
259+
context(returnValue);
260+
}
251261

252262
if (!item.moved) {
253263
// Deleted or brand new item. Unwatch or watch it accordingly.
254-
// This used to be on a setTimeout but this is not symmetric to the !array case.
255-
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
264+
if (options.synchWatch) {
265+
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
266+
} else {
267+
setTimeout(function () {
268+
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
269+
});
270+
}
256271
}
257272
});
258273
}, undefined, 'arrayChange')._watcher = context;
@@ -265,9 +280,16 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {
265280
if (returnValue !== undefined)
266281
context(returnValue);
267282

268-
if (options.mutable && typeof child() === 'object')
283+
if (options.mutable && typeof child() === 'object') {
269284
// Watch the new comer.
270-
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
285+
if (options.synchWatch) {
286+
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
287+
} else {
288+
setTimeout(function () {
289+
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
290+
});
291+
}
292+
}
271293
}
272294

273295
}, null, 'change')._watcher = context;

dist/ko-reactor.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)