Skip to content

Commit

Permalink
preparing 1.4.0-beta2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
bago committed Feb 8, 2018
1 parent 85a6925 commit 70a5e10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions dist/ko-reactor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! ko-reactor v1.4.0-beta
/*! ko-reactor v1.4.0-beta2
* The MIT License (MIT)
* Copyright (c) 2017 Ziad Jeeroburkhan */
// Deep observer plugin for Knockout http://knockoutjs.com/
Expand Down Expand Up @@ -39,6 +39,8 @@ ko.subscribable.fn['watch'] = function (targetOrCallback, options, evaluatorCall
/// { tagFields: true } -> Add the property '_fieldName' under each property for textual identification.<br/>
/// { tagFields: 'parentsOnly' } -> Same as above except that it is limited to parent properties only.<br/>
/// { oldValues: 3 } -> Keep the last three values for each subscribable under the property 'oldValues'.<br/>
/// { synchWatch: true } -> Use setTimeout to start watching new objects
/// { splitArrayChanges: false } -> receive a single notification for array changes as an array of "items" instead of multiple notifications
/// { seal: true } -> Prevent any subsequent watcher from watching the target again.<br/>
/// { unloop: true } -> Avoid circular paths through the use of a breadcrumb property '_watcher' set at each node level.<br/>
/// </param>
Expand Down Expand Up @@ -244,15 +246,28 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {
if (isArray) {
// Child is an observable array. Watch all changes within it.
child.subscribe(function (changes) {
ko.utils.arrayForEach(changes, function (item) {
var returnValue = evaluatorCallback.call(context, parents, child, item);
var returnValue;
if (options.splitArrayChanges === false) {
returnValue = evaluatorCallback.call(context, parents, child, changes);
if (returnValue !== undefined)
context(returnValue);
}
ko.utils.arrayForEach(changes, function (item) {
if (options.splitArrayChanges !== false) {
var returnValue = evaluatorCallback.call(context, parents, child, item);
if (returnValue !== undefined)
context(returnValue);
}

if (!item.moved) {
// Deleted or brand new item. Unwatch or watch it accordingly.
// This used to be on a setTimeout but this is not symmetric to the !array case.
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
if (options.synchWatch) {
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
} else {
setTimeout(function () {
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
});
}
}
});
}, undefined, 'arrayChange')._watcher = context;
Expand All @@ -265,9 +280,16 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {
if (returnValue !== undefined)
context(returnValue);

if (options.mutable && typeof child() === 'object')
if (options.mutable && typeof child() === 'object') {
// Watch the new comer.
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
if (options.synchWatch) {
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
} else {
setTimeout(function () {
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
});
}
}
}

}, null, 'change')._watcher = context;
Expand Down
4 changes: 2 additions & 2 deletions dist/ko-reactor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70a5e10

Please sign in to comment.