Skip to content

Commit

Permalink
synchWatch: true => async: false + 1.4.0 release
Browse files Browse the repository at this point in the history
Inverted option from "synchWatch: true" to "async: false" (introduced in @85a6925) as requested by @ZiadJ
Added 2018 copyright year, Removed version from source (it is automatically added in the build), Prepared 1.4.0 final release.
  • Loading branch information
bago committed Feb 22, 2018
1 parent 78f887f commit 00081ad
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function(grunt) {
var banner = [
"<%= pkg.name %> v<%= pkg.version %>",
"The MIT License (MIT)",
"Copyright (c) 2017 <%= pkg.author %>",
"Copyright (c) 2018 <%= pkg.author %>",
].join("\n * ").trim();

grunt.initConfig({
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Released under the [MIT License](http://en.wikipedia.org/wiki/MIT_License)

Copyright (c) 2015-2017 by Ziad Jeeroburkhan
Copyright (c) 2015-2018 by Ziad Jeeroburkhan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Once disposed your model will be "unwatched"<br/>
<b>Synchronous tracking:</b> (since 1.4.0)<br/>
By default when new objects are added to the tree, they are automatically "watched" asynchronously (e.g: in a setTimeout) in order to keep the system more responsive.
Sometimes this behaviour is not "expected", so you can use the ```synchWatch: true``` option to force watch to happen "inline".
Sometimes this behaviour is not "expected", so you can use the ```async: false``` option to force watch to happen "inline".
<b>Single notification for multiple array changes vs change by change notifications</b> (since 1.4.0)<br/>
By default when items are moved in an array you receive 2 different notifications, the first will report the "deleted item" and the second one will report the "added item".
Expand Down
11 changes: 5 additions & 6 deletions dist/ko-reactor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*! ko-reactor v1.4.0-beta3
/*! ko-reactor v1.4.0
* The MIT License (MIT)
* Copyright (c) 2017 Ziad Jeeroburkhan */
* Copyright (c) 2018 Ziad Jeeroburkhan */
// Deep observer plugin for Knockout http://knockoutjs.com/
// (c) Ziad Jeeroburkhan
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
// Version 1.3.8
; (function (factory) {
// CommonJS
if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
Expand Down Expand Up @@ -39,7 +38,7 @@ 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
/// { async: false } -> Start watching new objects synchronously
/// { 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/>
Expand Down Expand Up @@ -262,7 +261,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {

if (!item.moved) {
// Deleted or brand new item. Unwatch or watch it accordingly.
if (options.synchWatch) {
if (options.async === false) {
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
} else {
setTimeout(function () {
Expand All @@ -283,7 +282,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {

if (options.mutable && typeof child() === 'object') {
// Watch the new comer.
if (options.synchWatch) {
if (options.async === false) {
watchChildren(child(), (keepOffParentList ? null : child), parents, false, true);
} else {
setTimeout(function () {
Expand Down
6 changes: 3 additions & 3 deletions dist/ko-reactor.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"contributors": [
"Stefano Bagnara"
],
"version": "1.4.0-beta3",
"version": "1.4.0",
"repository": {
"type": "git",
"url": "https://github.com/ZiadJ/knockoutjs-reactor.git"
Expand Down
4 changes: 2 additions & 2 deletions spec/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('watching nested models', function() {

var answers = [];

var w = ko.watch(model, { depth: -1, oldValues: 1, mutable: true, /* tagParentsWithName: true */ tagFields: true, synchWatch: true }, listener.bind(undefined, answers), context);
var w = ko.watch(model, { depth: -1, oldValues: 1, mutable: true, /* tagParentsWithName: true */ tagFields: true, async: false }, listener.bind(undefined, answers), context);

console.log("##### ", "model.a(2) [1]");
model.a(2);
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('watching nested models', function() {

var answers = [];

var w = ko.watch(model, { depth: -1, oldValues: 1, mutable: true, /* tagParentsWithName: true */ tagFields: true, synchWatch: true }, listener.bind(undefined, answers), context);
var w = ko.watch(model, { depth: -1, oldValues: 1, mutable: true, /* tagParentsWithName: true */ tagFields: true, async: false }, listener.bind(undefined, answers), context);

console.log("##### ", "model.arr()[1].p('b2')");
model.arr()[1].p('b2');
Expand Down
7 changes: 3 additions & 4 deletions src/knockout.reactor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Deep observer plugin for Knockout http://knockoutjs.com/
// (c) Ziad Jeeroburkhan
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
// Version 1.3.8
; (function (factory) {
// CommonJS
if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
Expand Down Expand Up @@ -36,7 +35,7 @@ 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
/// { async: false } -> Start watching new objects synchronously
/// { 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/>
Expand Down Expand Up @@ -259,7 +258,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {

if (!item.moved) {
// Deleted or brand new item. Unwatch or watch it accordingly.
if (options.synchWatch) {
if (options.async === false) {
watchChildren(item.value, (keepOffParentList ? null : child), parents, item.status === 'deleted');
} else {
setTimeout(function () {
Expand All @@ -280,7 +279,7 @@ ko['watch'] = function (target, options, evaluatorCallback, context) {

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

0 comments on commit 00081ad

Please sign in to comment.