bobtail-json-cell
Advanced tools
Comparing version
@@ -276,29 +276,7 @@ (function (global, factory) { | ||
function _getProperty(getPath, basePath, obj, prop) { | ||
var _this3 = this; | ||
var val = obj[prop]; | ||
if (prop === '__proto__' || _underscore2.default.isFunction(val)) { | ||
return val; | ||
if (prop === '__proto__' || _underscore2.default.isFunction(obj[prop])) { | ||
return obj[prop]; | ||
} | ||
if (prop === UPDATE || prop === 'updateRxb' && !('updateRxb' in obj)) { | ||
return function (other) { | ||
return jsondiffpatch.patch(obj, jsondiffpatch.diff(obj, other)); | ||
}; | ||
} | ||
var path = getPath(prop); | ||
if (prop === 'length' && _underscore2.default.isArray(obj)) { | ||
var oldVal = obj.length; | ||
recorder.sub(this.onChange, function () { | ||
var newVal = (0, _lodash2.default)(_this3._base, path.slice(1)); // necessary because of wrapping in value field | ||
if (newVal !== oldVal) { | ||
oldVal = newVal; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} else { | ||
recorder.sub(this.onChange, function (patch) { | ||
return patchHas(patch, path); | ||
}); | ||
} | ||
this.subscribeProperty(getPath, obj, prop); | ||
// return new Proxy(deepGet(this._base, path), this.conf(path, obj)); | ||
@@ -317,13 +295,13 @@ if (_underscore2.default.isObject(val)) { | ||
var _this4 = _possibleConstructorReturn(this, (ObsJsonCell.__proto__ || Object.getPrototypeOf(ObsJsonCell)).call(this)); | ||
var _this3 = _possibleConstructorReturn(this, (ObsJsonCell.__proto__ || Object.getPrototypeOf(ObsJsonCell)).call(this)); | ||
_this4._base = _base; | ||
_this4.onChange = _this4._mkEv(function () { | ||
return jsondiffpatch.diff({}, _this4._base); | ||
_this3._base = _base; | ||
_this3.onChange = _this3._mkEv(function () { | ||
return jsondiffpatch.diff({}, _this3._base); | ||
}); | ||
_this4.onUnsafeMutation = _this4._mkEv(function () {}); | ||
_this4._updating(function () { | ||
return _this4._data = new Proxy({ value: _this4._base }, _this4.conf([], null)); | ||
_this3.onUnsafeMutation = _this3._mkEv(function () {}); | ||
_this3._updating(function () { | ||
return _this3._data = new Proxy({ value: _this3._base }, _this3.conf([], null)); | ||
}); | ||
return _this4; | ||
return _this3; | ||
} | ||
@@ -346,7 +324,7 @@ | ||
value: function _update(newVal) { | ||
var _this5 = this; | ||
var _this4 = this; | ||
this._updating(function () { | ||
var diff = jsondiffpatch.diff(_this5._data, { value: newVal }); | ||
jsondiffpatch.patch(_this5._data, diff); | ||
var diff = jsondiffpatch.diff(_this4._data, { value: newVal }); | ||
jsondiffpatch.patch(_this4._data, diff); | ||
}); | ||
@@ -363,6 +341,6 @@ return true; | ||
value: function readonly() { | ||
var _this6 = this; | ||
var _this5 = this; | ||
return new DepJsonCell(function () { | ||
return _this6.data; | ||
return _this5.data; | ||
}); | ||
@@ -373,6 +351,6 @@ } | ||
value: function mkDeleteProperty(getPath, basePath) { | ||
var _this7 = this; | ||
var _this6 = this; | ||
return function (obj, prop) { | ||
return _this7.deleteProperty(getPath, basePath, obj, prop); | ||
return _this6.deleteProperty(getPath, basePath, obj, prop); | ||
}; | ||
@@ -383,6 +361,6 @@ } | ||
value: function mkSetProperty(getPath, basePath) { | ||
var _this8 = this; | ||
var _this7 = this; | ||
return function (obj, prop, val) { | ||
return _this8.setProperty(getPath, basePath, obj, prop, val); | ||
return _this7.setProperty(getPath, basePath, obj, prop, val); | ||
}; | ||
@@ -393,6 +371,6 @@ } | ||
value: function mkGetProperty(getPath, basePath) { | ||
var _this9 = this; | ||
var _this8 = this; | ||
return function (obj, prop) { | ||
return _this9.getProperty(getPath, basePath, obj, prop); | ||
return _this8.getProperty(getPath, basePath, obj, prop); | ||
}; | ||
@@ -416,2 +394,24 @@ } | ||
}, { | ||
key: 'subscribeProperty', | ||
value: function subscribeProperty(getPath, obj, prop) { | ||
var _this9 = this; | ||
var path = getPath(prop); | ||
if (prop === 'length' && _underscore2.default.isArray(obj)) { | ||
var oldVal = obj.length; | ||
recorder.sub(this.onChange, function () { | ||
var newVal = (0, _lodash2.default)(_this9._base, path.slice(1)); // necessary because of wrapping in value field | ||
if (newVal !== oldVal) { | ||
oldVal = newVal; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} else { | ||
recorder.sub(this.onChange, function (patch) { | ||
return patchHas(patch, path); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: '_makeReadOnly', | ||
@@ -418,0 +418,0 @@ value: function _makeReadOnly() { |
@@ -1,1 +0,1 @@ | ||
!function(t,e){if("function"==typeof define&&define.amd)define("bobtail-json-cell",["exports","underscore","bobtail-rx","lodash.get","lodash.set","lodash.hasin","jsondiffpatch"],e);else if("undefined"!=typeof exports)e(exports,require("underscore"),require("bobtail-rx"),require("lodash.get"),require("lodash.set"),require("lodash.hasin"),require("jsondiffpatch"));else{var n={exports:{}};e(n.exports,t._,t.rx,t.lodashGet,t.lodashSet,t.lodashHasin,t.jsondiffpatch),t.bobtailJsonCell=n.exports}}(this,function(t,e,n,r,o,a,i){"use strict";function u(t){return t&&t.__esModule?t:{default:t}}function l(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function f(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t){return Array.isArray(t)?t:Array.from(t)}function h(t,e,n,r){var o=this;return b.snap(function(){var a=t(r);return O.stack.length>0&&(console.warn("Warning: deleting nested element at "+a.join(".")+" from within a bind context. Affected object:",n),o.onUnsafeMutation.pub({op:"delete",path:a,obj:n,prop:r,base:o._base})),O.mutating(function(){var t=n[r],a=x(e,[c({},r,t),0,0]);r in n&&(delete n[r],o.onChange.pub(a))}),!0})}function d(t,e,n,r,o){var a=this;return b.snap(function(){var i=t(r);return O.stack.length>0&&(console.warn("Warning: updating nested element at "+i.join(".")+" from within a bind context. Affected object:",n),a.onUnsafeMutation.pub({op:"set",path:i,obj:n,prop:r,val:o,base:a._base})),O.mutating(function(){var t=b.snap(function(){return n[r]}),i=j.diff(c({},r,t),c({},r,o));i&&(j.patch(n,i),a.onChange.pub(x(e,i)))}),!0})}function y(t,e,n,r){var o=this,a=n[r];if("__proto__"===r||v.default.isFunction(a))return a;if(r===A||"updateRxb"===r&&!("updateRxb"in n))return function(t){return j.patch(n,j.diff(n,t))};var i=t(r);if("length"===r&&v.default.isArray(n)){var u=n.length;O.sub(this.onChange,function(){var t=(0,_.default)(o._base,i.slice(1));return t!==u&&(u=t,!0)})}else O.sub(this.onChange,function(t){return C(t,i)});return v.default.isObject(a)?new Proxy(a,this.conf(t(r),n)):a}Object.defineProperty(t,"__esModule",{value:!0}),t.update=t.jsonCell=t.SrcJsonCell=t.DepJsonCell=t.DepMutationError=t.ObsJsonCell=t.UPDATE=t.patchHas=void 0,t.logReturn=function(t){return console.info(t),t};var v=u(e),b=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n),_=u(r),g=u(o),w=u(a),m=u(i),P=function(){function t(t,e){var n=[],r=!0,o=!1,a=void 0;try{for(var i,u=t[Symbol.iterator]();!(r=(i=u.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){o=!0,a=t}finally{try{!r&&u.return&&u.return()}finally{if(o)throw a}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),k=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),j=m.default.create({cloneDiffValues:!0}),O=b._recorder,C=t.patchHas=function t(e,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(v.default.isString(n))return t(e,n.split("."));if(!n.length)return!0;v.default.isArray(e)&&!r&&(r=!0,e=e[0]);var o=p(n),a=o[0],i=o.slice(1);if(v.default.isObject(e)){if(!r&&"a"===e._t){var u=""+a;return u in e?t(e[u],i,r):a in e&&t(e[a],i,r)}return a in e&&(1===n.length||t(e[a],i,r))}return!1},x=function(t,e){if(!t.length)return e;var n={};return(0,g.default)(n,t,e),n},A=t.UPDATE=Symbol("update"),S=t.ObsJsonCell=function(t){function e(t){l(this,e);var n=f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return n._base=t,n.onChange=n._mkEv(function(){return j.diff({},n._base)}),n.onUnsafeMutation=n._mkEv(function(){}),n._updating(function(){return n._data=new Proxy({value:n._base},n.conf([],null))}),n}return s(e,b.ObsBase),k(e,[{key:"_updating",value:function(t){this._oldUpdating=this._nowUpdating||!1,this._nowUpdating=!0;try{b.snap(t)}finally{this._nowUpdating=this._oldUpdating}return!0}},{key:"_update",value:function(t){var e=this;return this._updating(function(){var n=j.diff(e._data,{value:t});j.patch(e._data,n)}),!0}},{key:"all",value:function(){return this.data}},{key:"readonly",value:function(){var t=this;return new U(function(){return t.data})}},{key:"mkDeleteProperty",value:function(t,e){var n=this;return function(r,o){return n.deleteProperty(t,e,r,o)}}},{key:"mkSetProperty",value:function(t,e){var n=this;return function(r,o,a){return n.setProperty(t,e,r,o,a)}}},{key:"mkGetProperty",value:function(t,e){var n=this;return function(r,o){return n.getProperty(t,e,r,o)}}},{key:"deleteProperty",value:function(t,e,n,r){return h.call(this,t,e,n,r)}},{key:"setProperty",value:function(t,e,n,r,o){return d.call(this,t,e,n,r,o)}},{key:"getProperty",value:function(t,e,n,r){return y.call(this,t,e,n,r)}},{key:"_makeReadOnly",value:function(){var t=this.setProperty;this.setProperty=function(e,n,r,o,a){if(this._nowUpdating)return t.call(this,e,n,r,o,a);throw new E("Cannot mutate DepJsonCell!")};var e=this.deleteProperty;return this.deleteProperty=function(t,n,r,o){if(this._nowUpdating)return e.call(this,t,n,r,o);throw new E("Cannot mutate DepJsonCell!")},this}},{key:"conf",value:function(t){var e=this,n=function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.concat(n)};return{deleteProperty:this.mkDeleteProperty(n,t),set:this.mkSetProperty(n,t),get:this.mkGetProperty(n,t),has:function(t,r){var o=n(r).slice(1),a=r in t;return O.sub(e.onChange,function(t){var n=(0,w.default)(e._base,o);return a!==n&&(a=n,!0)}),a},ownKeys:function(n){return O.sub(e.onChange,function(e){var n=(0,_.default)(e,t);return!!n&&(!!v.default.isArray(n&&2!==n.length)||"a"===n._t&&v.default.chain(n).omit("_t").values().value().some())}),Reflect.ownKeys(n)}}}},{key:"data",get:function(){return this._data.value}}]),e}(),E=t.DepMutationError=function(t){function e(){var t;l(this,e);for(var n=arguments.length,r=Array(n),o=0;o<n;o++)r[o]=arguments[o];var a=f(this,(t=e.__proto__||Object.getPrototypeOf(e)).call.apply(t,[this].concat(r)));return Error.captureStackTrace(a,e),a}return s(e,Error),e}(),U=t.DepJsonCell=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l(this,e);var r=f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,n));r.f=t;var o=b.bind(r.f);return b.autoSub(o.onSet,function(t){var e=P(t,2),n=(e[0],e[1]);return r._update(n)}),r._makeReadOnly(),r}return s(e,S),e}(),D=t.SrcJsonCell=function(t){function e(t){return l(this,e),f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return s(e,S),k(e,[{key:"update",value:function(t){return this._update(t)}},{key:"data",set:function(t){this._update(t)},get:function(){return this._data.value}}]),e}();t.jsonCell=function(t){return new D(t).data},t.update=function(t,e){return b.snap(function(){var n=j.diff(t,e);return j.patch(t,n),!0})}}); | ||
!function(t,e){if("function"==typeof define&&define.amd)define("bobtail-json-cell",["exports","underscore","bobtail-rx","lodash.get","lodash.set","lodash.hasin","jsondiffpatch"],e);else if("undefined"!=typeof exports)e(exports,require("underscore"),require("bobtail-rx"),require("lodash.get"),require("lodash.set"),require("lodash.hasin"),require("jsondiffpatch"));else{var n={exports:{}};e(n.exports,t._,t.rx,t.lodashGet,t.lodashSet,t.lodashHasin,t.jsondiffpatch),t.bobtailJsonCell=n.exports}}(this,function(t,e,n,r,o,a,i){"use strict";function u(t){return t&&t.__esModule?t:{default:t}}function l(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function f(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t){return Array.isArray(t)?t:Array.from(t)}function h(t,e,n,r){var o=this;return b.snap(function(){var a=t(r);return O.stack.length>0&&(console.warn("Warning: deleting nested element at "+a.join(".")+" from within a bind context. Affected object:",n),o.onUnsafeMutation.pub({op:"delete",path:a,obj:n,prop:r,base:o._base})),O.mutating(function(){var t=n[r],a=x(e,[c({},r,t),0,0]);r in n&&(delete n[r],o.onChange.pub(a))}),!0})}function d(t,e,n,r,o){var a=this;return b.snap(function(){var i=t(r);return O.stack.length>0&&(console.warn("Warning: updating nested element at "+i.join(".")+" from within a bind context. Affected object:",n),a.onUnsafeMutation.pub({op:"set",path:i,obj:n,prop:r,val:o,base:a._base})),O.mutating(function(){var t=b.snap(function(){return n[r]}),i=j.diff(c({},r,t),c({},r,o));i&&(j.patch(n,i),a.onChange.pub(x(e,i)))}),!0})}function y(t,e,n,r){var o=n[r];return"__proto__"===r||v.default.isFunction(n[r])?n[r]:(this.subscribeProperty(t,n,r),v.default.isObject(o)?new Proxy(o,this.conf(t(r),n)):o)}Object.defineProperty(t,"__esModule",{value:!0}),t.update=t.jsonCell=t.SrcJsonCell=t.DepJsonCell=t.DepMutationError=t.ObsJsonCell=t.UPDATE=t.patchHas=void 0,t.logReturn=function(t){return console.info(t),t};var v=u(e),b=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n),_=u(r),g=u(o),P=u(a),w=u(i),m=function(){function t(t,e){var n=[],r=!0,o=!1,a=void 0;try{for(var i,u=t[Symbol.iterator]();!(r=(i=u.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){o=!0,a=t}finally{try{!r&&u.return&&u.return()}finally{if(o)throw a}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),k=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),j=w.default.create({cloneDiffValues:!0}),O=b._recorder,C=t.patchHas=function t(e,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(v.default.isString(n))return t(e,n.split("."));if(!n.length)return!0;v.default.isArray(e)&&!r&&(r=!0,e=e[0]);var o=p(n),a=o[0],i=o.slice(1);if(v.default.isObject(e)){if(!r&&"a"===e._t){var u=""+a;return u in e?t(e[u],i,r):a in e&&t(e[a],i,r)}return a in e&&(1===n.length||t(e[a],i,r))}return!1},x=function(t,e){if(!t.length)return e;var n={};return(0,g.default)(n,t,e),n},A=(t.UPDATE=Symbol("update"),t.ObsJsonCell=function(t){function e(t){l(this,e);var n=s(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return n._base=t,n.onChange=n._mkEv(function(){return j.diff({},n._base)}),n.onUnsafeMutation=n._mkEv(function(){}),n._updating(function(){return n._data=new Proxy({value:n._base},n.conf([],null))}),n}return f(e,b.ObsBase),k(e,[{key:"_updating",value:function(t){this._oldUpdating=this._nowUpdating||!1,this._nowUpdating=!0;try{b.snap(t)}finally{this._nowUpdating=this._oldUpdating}return!0}},{key:"_update",value:function(t){var e=this;return this._updating(function(){var n=j.diff(e._data,{value:t});j.patch(e._data,n)}),!0}},{key:"all",value:function(){return this.data}},{key:"readonly",value:function(){var t=this;return new E(function(){return t.data})}},{key:"mkDeleteProperty",value:function(t,e){var n=this;return function(r,o){return n.deleteProperty(t,e,r,o)}}},{key:"mkSetProperty",value:function(t,e){var n=this;return function(r,o,a){return n.setProperty(t,e,r,o,a)}}},{key:"mkGetProperty",value:function(t,e){var n=this;return function(r,o){return n.getProperty(t,e,r,o)}}},{key:"deleteProperty",value:function(t,e,n,r){return h.call(this,t,e,n,r)}},{key:"setProperty",value:function(t,e,n,r,o){return d.call(this,t,e,n,r,o)}},{key:"getProperty",value:function(t,e,n,r){return y.call(this,t,e,n,r)}},{key:"subscribeProperty",value:function(t,e,n){var r=this,o=t(n);if("length"===n&&v.default.isArray(e)){var a=e.length;O.sub(this.onChange,function(){var t=(0,_.default)(r._base,o.slice(1));return t!==a&&(a=t,!0)})}else O.sub(this.onChange,function(t){return C(t,o)})}},{key:"_makeReadOnly",value:function(){var t=this.setProperty;this.setProperty=function(e,n,r,o,a){if(this._nowUpdating)return t.call(this,e,n,r,o,a);throw new S("Cannot mutate DepJsonCell!")};var e=this.deleteProperty;return this.deleteProperty=function(t,n,r,o){if(this._nowUpdating)return e.call(this,t,n,r,o);throw new S("Cannot mutate DepJsonCell!")},this}},{key:"conf",value:function(t){var e=this,n=function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.concat(n)};return{deleteProperty:this.mkDeleteProperty(n,t),set:this.mkSetProperty(n,t),get:this.mkGetProperty(n,t),has:function(t,r){var o=n(r).slice(1),a=r in t;return O.sub(e.onChange,function(t){var n=(0,P.default)(e._base,o);return a!==n&&(a=n,!0)}),a},ownKeys:function(n){return O.sub(e.onChange,function(e){var n=(0,_.default)(e,t);return!!n&&(!!v.default.isArray(n&&2!==n.length)||"a"===n._t&&v.default.chain(n).omit("_t").values().value().some())}),Reflect.ownKeys(n)}}}},{key:"data",get:function(){return this._data.value}}]),e}()),S=t.DepMutationError=function(t){function e(){var t;l(this,e);for(var n=arguments.length,r=Array(n),o=0;o<n;o++)r[o]=arguments[o];var a=s(this,(t=e.__proto__||Object.getPrototypeOf(e)).call.apply(t,[this].concat(r)));return Error.captureStackTrace(a,e),a}return f(e,Error),e}(),E=t.DepJsonCell=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l(this,e);var r=s(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,n));r.f=t;var o=b.bind(r.f);return b.autoSub(o.onSet,function(t){var e=m(t,2),n=(e[0],e[1]);return r._update(n)}),r._makeReadOnly(),r}return f(e,A),e}(),U=t.SrcJsonCell=function(t){function e(t){return l(this,e),s(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return f(e,A),k(e,[{key:"update",value:function(t){return this._update(t)}},{key:"data",set:function(t){this._update(t)},get:function(){return this._data.value}}]),e}();t.jsonCell=function(t){return new U(t).data},t.update=function(t,e){return b.snap(function(){var n=j.diff(t,e);return j.patch(t,n),!0})}}); |
{ | ||
"name": "bobtail-json-cell", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -154,3 +154,3 @@ import nn from 'nevernull'; | ||
describe('JsonCell', () => { | ||
describe('SrcJsonCell', () => { | ||
it('should support primitive values', () => { | ||
@@ -166,2 +166,14 @@ let x = new SrcJsonCell(42); | ||
}); | ||
}); | ||
describe('arrays', () => { | ||
it('should emit change events when splice is called', () => { | ||
let src = new SrcJsonCell([1,2,3,4]); | ||
let dep = bind(() => src.data); | ||
expect(dep.raw()).toEqual([1,2,3,4]); | ||
src.data.splice(0,1); | ||
expect(dep.raw()).toEqual([2,3,4]); | ||
src.data.splice(0,0,1); | ||
expect(dep.raw()).toEqual([1,2,3,4]); | ||
}) | ||
}); |
@@ -105,3 +105,3 @@ import _ from 'underscore'; | ||
jsondiffpatch.patch(obj, diff); | ||
this.onChange.pub(prefixDiff(basePath, diff)); | ||
this.onChange.pub(prefixDiff(basePath, diff)); | ||
} | ||
@@ -115,23 +115,6 @@ }); | ||
let val = obj[prop]; | ||
if (prop === '__proto__' || _.isFunction(val)) { | ||
return val; | ||
if (prop === '__proto__' || _.isFunction(obj[prop])) { | ||
return obj[prop]; | ||
} | ||
if (prop === UPDATE || (prop === 'updateRxb' && !('updateRxb' in obj))) { | ||
return other => jsondiffpatch.patch(obj, jsondiffpatch.diff(obj, other)); | ||
} | ||
let path = getPath(prop); | ||
if (prop === 'length' && _.isArray(obj)) { | ||
let oldVal = obj.length; | ||
recorder.sub(this.onChange, () => { | ||
let newVal = deepGet(this._base, path.slice(1)); // necessary because of wrapping in value field | ||
if(newVal !== oldVal){ | ||
oldVal = newVal; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
else { | ||
recorder.sub(this.onChange, patch => patchHas(patch, path)); | ||
} | ||
this.subscribeProperty(getPath, obj, prop); | ||
// return new Proxy(deepGet(this._base, path), this.conf(path, obj)); | ||
@@ -198,2 +181,20 @@ if (_.isObject(val)) { | ||
subscribeProperty(getPath, obj, prop) { | ||
let path = getPath(prop); | ||
if (prop === 'length' && _.isArray(obj)) { | ||
let oldVal = obj.length; | ||
recorder.sub(this.onChange, () => { | ||
let newVal = deepGet(this._base, path.slice(1)); // necessary because of wrapping in value field | ||
if(newVal !== oldVal){ | ||
oldVal = newVal; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
else { | ||
recorder.sub(this.onChange, patch => patchHas(patch, path)); | ||
} | ||
} | ||
_makeReadOnly() { | ||
@@ -200,0 +201,0 @@ let oldSet = this.setProperty; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
76245
0.33%932
1.19%0
-100%