diff --git a/dist/ko-reactor.js b/dist/ko-reactor.js index 27629e8..907b50e 100644 --- a/dist/ko-reactor.js +++ b/dist/ko-reactor.js @@ -198,8 +198,10 @@ ko['watch'] = function (target, options, evaluatorCallback, context) { // Subscriptions are stored under either the _subscriptions field for the debug version // or the F, H or M fields when minified depending on the version used. + // NOTE: we used to use ko.DEBUG to detect the debug versionbut it was removed in 3.4.0+, + // so we now check the existence of a "subscription" function. var subscriptionsField; - switch (ko.DEBUG || ko.version) { + switch (typeof ko.subscription == 'function' || ko.version) { case true: subscriptionsField = '_subscriptions'; break; case "3.0.0": subscriptionsField = 'F'; break; case "3.1.0": subscriptionsField = 'H'; break; diff --git a/dist/ko-reactor.min.js b/dist/ko-reactor.min.js index f0ecdd9..3cc9446 100644 --- a/dist/ko-reactor.min.js +++ b/dist/ko-reactor.min.js @@ -1 +1 @@ -!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout")):"function"==typeof define&&define.amd?define(["knockout"],a):a(window.ko)}(function(a){a.subscribable.fn.watch=function(b,c,d,e){var f=typeof b;return"boolean"===f||"undefined"===f?a.watch(this,{enabled:b!==!1}):"function"!==f||a.isSubscribable(b)?a.watch(b,c,d,e||this):a.watch(this,c||{},b,e||this),this},a.watch=function(b,c,d,e){function f(i,j,k,l,m,n){if(i&&0!==c.depth&&(-1===c.depth||k.length<(c.depth||1))){if(c.watchedOnly&&!i.watchable&&i!=b)return;if((c.enabled===!1||c.enabled===!0)&&(i.watchable=c.enabled),i.watchable===!1)return;c.seal===!0&&(i.watchable=!1);var o=typeof i;if("object"===o||"function"===o){if(i._watcher===e)return;if(c.hide&&a.utils.arrayIndexOf(c.hide,i)>-1)return;var p=[].concat(k,j&&j!==b?j:[]);if("function"!==o){if("[object Object]"===Object.prototype.toString.call(i))a.utils.objectForEach(i,function(b,d){if(d=c.getter?c.getter.call(e,p,i,b):d){if(c.wrap){var g=Object.prototype.toString.call(d);"[object Function]"!==g&&"[object Object]"!==g&&(c.beforeWrap&&c.beforeWrap.call(e,p,i,d)===!1||(d=i[b]="[object Array]"===g?a.observableArray(d):a.observable(d)))}c.unloop&&(d._watcher=l?void 0:e);var h=f(d,m?null:i,p,l,null,b);c.tagFields&&void 0===d._fieldName&&(h||"parentsOnly"!==c.tagFields&&"function"==typeof d||"object"==typeof d)&&(d._fieldName=b)}});else if(c.hideArrays!==!0)for(var q=0;q=0;d--)b.change[d]._watcher===e&&b.change[d].dispose();if(b.beforeChange&&(c.mutable||c.oldValues>0))for(var d=b.beforeChange.length-1;d>=0;d--)b.beforeChange[d]._watcher===e&&b.beforeChange[d].dispose();if(b.arrayChange)for(var d=b.arrayChange.length-1;d>=0;d--)b.arrayChange[d]._watcher===e&&b.arrayChange[d].dispose()}function h(b,g,h,i){g?b.subscribe(function(c){a.utils.arrayForEach(c,function(a){var c=d.call(e,h,b,a);void 0!==c&&e(c),a.moved||setTimeout(function(){f(a.value,i?null:b,h,"deleted"===a.status)},0)})},void 0,"arrayChange")._watcher=e:(b.subscribe(function(){if(b.watchable!==!1){var a=d.call(e,h,b);void 0!==a&&e(a),c.mutable&&"object"==typeof b()&&f(b(),i?null:b,h)}},null,"change")._watcher=e,(c.oldValues>0||c.mutable)&&(b.subscribe(function(a){if(c.oldValues>0){var d=b.oldValues?b.oldValues:b.oldValues=[];for(d.unshift(a);d.length>c.oldValues;)d.pop()}c.mutable&&"object"==typeof a&&f(a,i?null:b,h,!1,!0)},null,"beforeChange")._watcher=e))}"function"==typeof c&&(e=e||d,d=c,c={}),e=e||this;var i;switch(a.DEBUG||a.version){case!0:i="_subscriptions";break;case"3.0.0":i="F";break;case"3.1.0":i="H";break;case"3.2.0":i="M";break;case"3.3.0":i="G";break;case"3.4.0":i="K";break;case"3.4.1":i="K";break;default:throw"Unsupported Knockout version. Only v3.0.0 to v3.4.1 are supported when minified. Current version is "+a.version}return"function"!=typeof b||a.isSubscribable(b)?(f(b,null,[]),{dispose:function(){f(b,null,[],!0)}}):a.computed(b,d,c)}});window.foo = "1.3.8"; \ No newline at end of file +!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout")):"function"==typeof define&&define.amd?define(["knockout"],a):a(window.ko)}(function(a){a.subscribable.fn.watch=function(b,c,d,e){var f=typeof b;return"boolean"===f||"undefined"===f?a.watch(this,{enabled:b!==!1}):"function"!==f||a.isSubscribable(b)?a.watch(b,c,d,e||this):a.watch(this,c||{},b,e||this),this},a.watch=function(b,c,d,e){function f(i,j,k,l,m,n){if(i&&0!==c.depth&&(-1===c.depth||k.length<(c.depth||1))){if(c.watchedOnly&&!i.watchable&&i!=b)return;if((c.enabled===!1||c.enabled===!0)&&(i.watchable=c.enabled),i.watchable===!1)return;c.seal===!0&&(i.watchable=!1);var o=typeof i;if("object"===o||"function"===o){if(i._watcher===e)return;if(c.hide&&a.utils.arrayIndexOf(c.hide,i)>-1)return;var p=[].concat(k,j&&j!==b?j:[]);if("function"!==o){if("[object Object]"===Object.prototype.toString.call(i))a.utils.objectForEach(i,function(b,d){if(d=c.getter?c.getter.call(e,p,i,b):d){if(c.wrap){var g=Object.prototype.toString.call(d);"[object Function]"!==g&&"[object Object]"!==g&&(c.beforeWrap&&c.beforeWrap.call(e,p,i,d)===!1||(d=i[b]="[object Array]"===g?a.observableArray(d):a.observable(d)))}c.unloop&&(d._watcher=l?void 0:e);var h=f(d,m?null:i,p,l,null,b);c.tagFields&&void 0===d._fieldName&&(h||"parentsOnly"!==c.tagFields&&"function"==typeof d||"object"==typeof d)&&(d._fieldName=b)}});else if(c.hideArrays!==!0)for(var q=0;q=0;d--)b.change[d]._watcher===e&&b.change[d].dispose();if(b.beforeChange&&(c.mutable||c.oldValues>0))for(var d=b.beforeChange.length-1;d>=0;d--)b.beforeChange[d]._watcher===e&&b.beforeChange[d].dispose();if(b.arrayChange)for(var d=b.arrayChange.length-1;d>=0;d--)b.arrayChange[d]._watcher===e&&b.arrayChange[d].dispose()}function h(b,g,h,i){g?b.subscribe(function(c){a.utils.arrayForEach(c,function(a){var c=d.call(e,h,b,a);void 0!==c&&e(c),a.moved||setTimeout(function(){f(a.value,i?null:b,h,"deleted"===a.status)},0)})},void 0,"arrayChange")._watcher=e:(b.subscribe(function(){if(b.watchable!==!1){var a=d.call(e,h,b);void 0!==a&&e(a),c.mutable&&"object"==typeof b()&&f(b(),i?null:b,h)}},null,"change")._watcher=e,(c.oldValues>0||c.mutable)&&(b.subscribe(function(a){if(c.oldValues>0){var d=b.oldValues?b.oldValues:b.oldValues=[];for(d.unshift(a);d.length>c.oldValues;)d.pop()}c.mutable&&"object"==typeof a&&f(a,i?null:b,h,!1,!0)},null,"beforeChange")._watcher=e))}"function"==typeof c&&(e=e||d,d=c,c={}),e=e||this;var i;switch("function"==typeof a.subscription||a.version){case!0:i="_subscriptions";break;case"3.0.0":i="F";break;case"3.1.0":i="H";break;case"3.2.0":i="M";break;case"3.3.0":i="G";break;case"3.4.0":i="K";break;case"3.4.1":i="K";break;default:throw"Unsupported Knockout version. Only v3.0.0 to v3.4.1 are supported when minified. Current version is "+a.version}return"function"!=typeof b||a.isSubscribable(b)?(f(b,null,[]),{dispose:function(){f(b,null,[],!0)}}):a.computed(b,d,c)}});window.foo = "1.3.9"; \ No newline at end of file diff --git a/package.json b/package.json index bb0aefa..38d0135 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ko-reactor", "author": "Ziad Jeeroburkhan", - "version": "1.3.8", + "version": "1.3.9", "repository": { "type": "git", "url": "https://github.com/ZiadJ/knockoutjs-reactor.git" diff --git a/src/knockout.reactor.js b/src/knockout.reactor.js index 27629e8..907b50e 100644 --- a/src/knockout.reactor.js +++ b/src/knockout.reactor.js @@ -198,8 +198,10 @@ ko['watch'] = function (target, options, evaluatorCallback, context) { // Subscriptions are stored under either the _subscriptions field for the debug version // or the F, H or M fields when minified depending on the version used. + // NOTE: we used to use ko.DEBUG to detect the debug versionbut it was removed in 3.4.0+, + // so we now check the existence of a "subscription" function. var subscriptionsField; - switch (ko.DEBUG || ko.version) { + switch (typeof ko.subscription == 'function' || ko.version) { case true: subscriptionsField = '_subscriptions'; break; case "3.0.0": subscriptionsField = 'F'; break; case "3.1.0": subscriptionsField = 'H'; break;