-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
Fixes #45 (compatibility with KO 3.4.2), Fixes #46 (forget to unwatch objects), Fixes #47 (bad parents in notification after object swap), Fixes #48 (basic test suite). Updated dev dependencies, add license/version banner to dist files.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
"homepage": "https://github.com/ZiadJ/knockoutjs-reactor.git", | ||
"authors": [ | ||
"Ziad Jeeroburkhan", | ||
"Jacob Kelley <[email protected]>" | ||
"Jacob Kelley <[email protected]>", | ||
"Stefano Bagnara <[email protected]>" | ||
], | ||
"description": "Deeply watches observable changes", | ||
"main": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/*! ko-reactor v1.4.0-beta | ||
* The MIT License (MIT) | ||
* Copyright (c) 2017 Ziad Jeeroburkhan */ | ||
// Deep observer plugin for Knockout http://knockoutjs.com/ | ||
// (c) Ziad Jeeroburkhan | ||
// License: MIT (http://www.opensource.org/licenses/mit-license.php) | ||
|
@@ -209,7 +212,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) { | |
case "3.3.0": subscriptionsField = 'G'; break; | ||
case "3.4.0": subscriptionsField = 'K'; break; | ||
case "3.4.1": subscriptionsField = 'K'; break; | ||
case "3.4.2": subscriptionsField = 'K'; break; | ||
case "3.4.2": subscriptionsField = 'F'; break; | ||
default: throw "Unsupported Knockout version. Only v3.0.0 to v3.4.2 are supported when minified. Current version is " + ko.version; | ||
} | ||
|
||
|
@@ -248,9 +251,8 @@ ko['watch'] = function (target, options, evaluatorCallback, context) { | |
|
||
if (!item.moved) { | ||
// Deleted or brand new item. Unwatch or watch it accordingly. | ||
setTimeout(function () { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ZiadJ
Owner
|
||
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted'); | ||
}, 0); | ||
// 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'); | ||
} | ||
}); | ||
}, undefined, 'arrayChange')._watcher = context; | ||
|
@@ -265,7 +267,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) { | |
|
||
if (options.mutable && typeof child() === 'object') | ||
// Watch the new comer. | ||
watchChildren(child(), (keepOffParentList ? null : child), parents); | ||
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true); | ||
} | ||
|
||
}, null, 'change')._watcher = context; | ||
|
@@ -286,7 +288,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) { | |
|
||
if (options.mutable && typeof oldValue === 'object') | ||
// Clean up all subscriptions for the old child object. | ||
watchChildren(oldValue, (keepOffParentList ? null : child), parents, false, true); | ||
watchChildren(oldValue, (keepOffParentList ? null : child), parents, true, true); | ||
|
||
}, null, 'beforeChange')._watcher = context; | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Why is this "setTimeout" here in the arrayChange handler while the "change" handler doesn't use a timeout?
The timeout makes synchronous tests/operations to fail (e.g: adding a new object to an array and in the same "thread" make changes to the same object you are not notified because it will be watched in a setTimeout).