bobtail-json-cell
Advanced tools
Comparing version
@@ -494,2 +494,11 @@ (function (global, factory) { | ||
}, { | ||
key: 'snapGet', | ||
value: function snapGet(path) { | ||
var _this11 = this; | ||
return rx.snap(function () { | ||
return (0, _lodash2.default)(_this11.data, path); | ||
}); | ||
} | ||
}, { | ||
key: 'data', | ||
@@ -517,6 +526,6 @@ get: function get() { | ||
var _this11 = _possibleConstructorReturn(this, (_ref2 = DepMutationError.__proto__ || Object.getPrototypeOf(DepMutationError)).call.apply(_ref2, [this].concat(args))); | ||
var _this12 = _possibleConstructorReturn(this, (_ref2 = DepMutationError.__proto__ || Object.getPrototypeOf(DepMutationError)).call.apply(_ref2, [this].concat(args))); | ||
Error.captureStackTrace(_this11, DepMutationError); | ||
return _this11; | ||
Error.captureStackTrace(_this12, DepMutationError); | ||
return _this12; | ||
} | ||
@@ -535,6 +544,6 @@ | ||
var _this12 = _possibleConstructorReturn(this, (DepJsonCell.__proto__ || Object.getPrototypeOf(DepJsonCell)).call(this, init)); | ||
var _this13 = _possibleConstructorReturn(this, (DepJsonCell.__proto__ || Object.getPrototypeOf(DepJsonCell)).call(this, init)); | ||
_this12.f = f; | ||
var c = rx.bind(_this12.f); | ||
_this13.f = f; | ||
var c = rx.bind(_this13.f); | ||
rx.autoSub(c.onSet, function (_ref3) { | ||
@@ -545,6 +554,6 @@ var _ref4 = _slicedToArray(_ref3, 2), | ||
return _this12._update(n); | ||
return _this13._update(n); | ||
}); | ||
_this12._makeReadOnly(); | ||
return _this12; | ||
_this13._makeReadOnly(); | ||
return _this13; | ||
} | ||
@@ -551,0 +560,0 @@ |
@@ -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","lodash.clonedeep","jsondiffpatch"],e);else if("undefined"!=typeof exports)e(exports,require("underscore"),require("bobtail-rx"),require("lodash.get"),require("lodash.set"),require("lodash.hasin"),require("lodash.clonedeep"),require("jsondiffpatch"));else{var n={exports:{}};e(n.exports,t._,t.rx,t.lodashGet,t.lodashSet,t.lodashHasin,t.lodashClonedeep,t.jsondiffpatch),t.bobtailJsonCell=n.exports}}(this,function(t,e,n,r,o,a,i,u){"use strict";function l(t){return t&&t.__esModule?t:{default:t}}function s(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 c(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 p(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(t){return Array.isArray(t)?t:Array.from(t)}function d(t,e,n,r){var o=this;return _.snap(function(){var a=t(r);return x.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:_.snap(function(){return o.data})})),x.mutating(function(){var t=n[r],a=A(e,[p({},r,t),0,0]);r in n&&(delete n[r],o.onChange.pub(a))}),!0})}function y(t,e,n,r,o){var a=this;return _.snap(function(){var i=t(r);return x.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:_.snap(function(){return a.data})})),x.mutating(function(){var t=_.snap(function(){return n[r]}),i=C.diff(p({},r,t),p({},r,o));i&&(C.patch(n,i),a.onChange.pub(A(e,i)))}),!0})}function v(t,e,n,r){var o=n[r];return"IS_PROXY_SYM"===r||("__proto__"===r||b.default.isFunction(n[r])?n[r]:(this.subscribeProperty(t,n,r),b.default.isObject(o)?new Proxy(o,this.conf(t(r))):o))}Object.defineProperty(t,"__esModule",{value:!0}),t.update=t.jsonCell=t.SrcJsonCell=t.DepJsonCell=t.DepMutationError=t.ObsJsonCell=t.UPDATE=t.patchHas=t.IS_PROXY_SYM=void 0,t.logReturn=function(t){return console.info(t),t};var b=l(e),_=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),g=l(r),P=l(o),w=l(a),k=l(i),m=l(u),O=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")}}(),j=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}}(),C=m.default.create({cloneDiffValues:!0}),x=_._recorder,S=(t.IS_PROXY_SYM=Symbol("is_proxy"),t.patchHas=function t(e,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(b.default.isString(n))return t(e,n.split("."));if(!n.length)return!0;b.default.isArray(e)&&!r&&(r=!0,e=e[0]);var o=h(n),a=o[0],i=o.slice(1);if(b.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}),A=function(t,e){if(!t.length)return e;var n={};return(0,P.default)(n,t,e),n},E=(t.UPDATE=Symbol("update"),t.ObsJsonCell=function(t){function e(t){s(this,e);var n=f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return n.onChange=n._mkEv(function(){return C.diff({},t)}),n.onUnsafeMutation=n._mkEv(function(){}),n._base={value:t},n}return c(e,_.ObsBase),j(e,[{key:"_proxify",value:function(){return new Proxy(this._base,this.conf([]))}},{key:"_updating",value:function(t){var e=this._nowUpdating||!1;this._nowUpdating=!0;try{_.snap(t)}finally{this._nowUpdating=e}return!0}},{key:"_update",value:function(t){var e=this;return this._updating(function(){var n=C.diff(e._base,{value:t});C.patch(e._proxify(),n)}),!0}},{key:"all",value:function(){return this.data}},{key:"cloneRaw",value:function(){return(0,k.default)(this._base.value)}},{key:"readonly",value:function(){var t=this;return new M(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 d.call(this,t,e,n,r)}},{key:"setProperty",value:function(t,e,n,r,o){return y.call(this,t,e,n,r,o)}},{key:"getProperty",value:function(t,e,n,r){return v.call(this,t,e,n,r)}},{key:"subscribeProperty",value:function(t,e,n){var r=this,o=t(n);if("length"===n&&b.default.isArray(e)){var a=e.length;x.sub(this.onChange,function(){var t=_.snap(function(){return(0,g.default)(r._base,o)});return t!==a&&(a=t,!0)})}else x.sub(this.onChange,function(t){return S(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 D("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 D("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),a=r in t;return x.sub(e.onChange,function(t){var n=(0,w.default)(e._base,o);return a!==n&&(a=n,!0)}),a},ownKeys:function(n){return x.sub(e.onChange,function(e){var n=(0,g.default)(e,t);return!!n&&(!!b.default.isArray(n&&2!==n.length)||"a"===n._t&&b.default.chain(n).omit("_t").values().value().some())}),Reflect.ownKeys(n)}}}},{key:"data",get:function(){return this._proxify().value}}]),e}()),D=t.DepMutationError=function(t){function e(){var t;s(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 c(e,Error),e}(),M=t.DepJsonCell=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e);var r=f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,n));r.f=t;var o=_.bind(r.f);return _.autoSub(o.onSet,function(t){var e=O(t,2),n=(e[0],e[1]);return r._update(n)}),r._makeReadOnly(),r}return c(e,E),e}(),U=t.SrcJsonCell=function(t){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return s(this,e),f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return c(e,E),j(e,[{key:"update",value:function(t){return this._update(t)}},{key:"data",set:function(t){this._update(t)},get:function(){return this._proxify().value}}]),e}();t.jsonCell=function(t){return new U(t).data},t.update=function(t,e){return _.snap(function(){var n=C.diff(t,e);return C.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","lodash.clonedeep","jsondiffpatch"],e);else if("undefined"!=typeof exports)e(exports,require("underscore"),require("bobtail-rx"),require("lodash.get"),require("lodash.set"),require("lodash.hasin"),require("lodash.clonedeep"),require("jsondiffpatch"));else{var n={exports:{}};e(n.exports,t._,t.rx,t.lodashGet,t.lodashSet,t.lodashHasin,t.lodashClonedeep,t.jsondiffpatch),t.bobtailJsonCell=n.exports}}(this,function(t,e,n,r,o,a,u,i){"use strict";function l(t){return t&&t.__esModule?t:{default:t}}function s(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 c(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 p(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(t){return Array.isArray(t)?t:Array.from(t)}function d(t,e,n,r){var o=this;return _.snap(function(){var a=t(r);return x.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:_.snap(function(){return o.data})})),x.mutating(function(){var t=n[r],a=A(e,[p({},r,t),0,0]);r in n&&(delete n[r],o.onChange.pub(a))}),!0})}function y(t,e,n,r,o){var a=this;return _.snap(function(){var u=t(r);return x.stack.length>0&&(console.warn("Warning: updating nested element at "+u.join(".")+" from within a bind context. Affected object:",n),a.onUnsafeMutation.pub({op:"set",path:u,obj:n,prop:r,val:o,base:_.snap(function(){return a.data})})),x.mutating(function(){var t=_.snap(function(){return n[r]}),u=C.diff(p({},r,t),p({},r,o));u&&(C.patch(n,u),a.onChange.pub(A(e,u)))}),!0})}function v(t,e,n,r){var o=n[r];return"IS_PROXY_SYM"===r||("__proto__"===r||b.default.isFunction(n[r])?n[r]:(this.subscribeProperty(t,n,r),b.default.isObject(o)?new Proxy(o,this.conf(t(r))):o))}Object.defineProperty(t,"__esModule",{value:!0}),t.update=t.jsonCell=t.SrcJsonCell=t.DepJsonCell=t.DepMutationError=t.ObsJsonCell=t.UPDATE=t.patchHas=t.IS_PROXY_SYM=void 0,t.logReturn=function(t){return console.info(t),t};var b=l(e),_=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),g=l(r),P=l(o),k=l(a),w=l(u),m=l(i),O=function(){function t(t,e){var n=[],r=!0,o=!1,a=void 0;try{for(var u,i=t[Symbol.iterator]();!(r=(u=i.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,a=t}finally{try{!r&&i.return&&i.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")}}(),j=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}}(),C=m.default.create({cloneDiffValues:!0}),x=_._recorder,S=(t.IS_PROXY_SYM=Symbol("is_proxy"),t.patchHas=function t(e,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(b.default.isString(n))return t(e,n.split("."));if(!n.length)return!0;b.default.isArray(e)&&!r&&(r=!0,e=e[0]);var o=h(n),a=o[0],u=o.slice(1);if(b.default.isObject(e)){if(!r&&"a"===e._t){var i=""+a;return i in e?t(e[i],u,r):a in e&&t(e[a],u,r)}return a in e&&(1===n.length||t(e[a],u,r))}return!1}),A=function(t,e){if(!t.length)return e;var n={};return(0,P.default)(n,t,e),n},E=(t.UPDATE=Symbol("update"),t.ObsJsonCell=function(t){function e(t){s(this,e);var n=f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return n.onChange=n._mkEv(function(){return C.diff({},t)}),n.onUnsafeMutation=n._mkEv(function(){}),n._base={value:t},n}return c(e,_.ObsBase),j(e,[{key:"_proxify",value:function(){return new Proxy(this._base,this.conf([]))}},{key:"_updating",value:function(t){var e=this._nowUpdating||!1;this._nowUpdating=!0;try{_.snap(t)}finally{this._nowUpdating=e}return!0}},{key:"_update",value:function(t){var e=this;return this._updating(function(){var n=C.diff(e._base,{value:t});C.patch(e._proxify(),n)}),!0}},{key:"all",value:function(){return this.data}},{key:"cloneRaw",value:function(){return(0,w.default)(this._base.value)}},{key:"readonly",value:function(){var t=this;return new M(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 d.call(this,t,e,n,r)}},{key:"setProperty",value:function(t,e,n,r,o){return y.call(this,t,e,n,r,o)}},{key:"getProperty",value:function(t,e,n,r){return v.call(this,t,e,n,r)}},{key:"subscribeProperty",value:function(t,e,n){var r=this,o=t(n);if("length"===n&&b.default.isArray(e)){var a=e.length;x.sub(this.onChange,function(){var t=_.snap(function(){return(0,g.default)(r._base,o)});return t!==a&&(a=t,!0)})}else x.sub(this.onChange,function(t){return S(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 D("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 D("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),a=r in t;return x.sub(e.onChange,function(t){var n=(0,k.default)(e._base,o);return a!==n&&(a=n,!0)}),a},ownKeys:function(n){return x.sub(e.onChange,function(e){var n=(0,g.default)(e,t);return!!n&&(!!b.default.isArray(n&&2!==n.length)||"a"===n._t&&b.default.chain(n).omit("_t").values().value().some())}),Reflect.ownKeys(n)}}}},{key:"snapGet",value:function(t){var e=this;return _.snap(function(){return(0,g.default)(e.data,t)})}},{key:"data",get:function(){return this._proxify().value}}]),e}()),D=t.DepMutationError=function(t){function e(){var t;s(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 c(e,Error),e}(),M=t.DepJsonCell=function(t){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e);var r=f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,n));r.f=t;var o=_.bind(r.f);return _.autoSub(o.onSet,function(t){var e=O(t,2),n=(e[0],e[1]);return r._update(n)}),r._makeReadOnly(),r}return c(e,E),e}(),U=t.SrcJsonCell=function(t){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return s(this,e),f(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return c(e,E),j(e,[{key:"update",value:function(t){return this._update(t)}},{key:"data",set:function(t){this._update(t)},get:function(){return this._proxify().value}}]),e}();t.jsonCell=function(t){return new U(t).data},t.update=function(t,e){return _.snap(function(){var n=C.diff(t,e);return C.patch(t,n),!0})}}); |
{ | ||
"name": "bobtail-json-cell", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "", | ||
@@ -42,3 +42,2 @@ "main": "dist/main.js", | ||
"dependencies": { | ||
"bobtail-rx": ">=2.1.1", | ||
"jsondiffpatch": "^0.2.4", | ||
@@ -51,3 +50,6 @@ "lodash.clonedeep": "^4.5.0", | ||
"underscore": "^1.8.3" | ||
}, | ||
"peerDependencies": { | ||
"bobtail-rx": ">=2.1.1" | ||
} | ||
} |
@@ -218,3 +218,3 @@ import nn from 'nevernull'; | ||
describe('nullification', () => { | ||
describe('nullified cells', () => { | ||
it("should work even after being reset to null", () => { | ||
@@ -227,2 +227,27 @@ // This previously caused breakages due to reliance on the old _base attribute. | ||
}); | ||
}); | ||
describe('snapGet', () => { | ||
it("Should not subscribe dependencies", () => { | ||
let cell = new SrcJsonCell({a: {b: 1, c: 2}, d: 3}); | ||
let x = bind(() => cell.snapGet('a.b')); | ||
expect(x.raw()).toBe(1); | ||
cell.data.a.b = 2; | ||
expect(x.raw()).toBe(1); // should not update | ||
}); | ||
it("sub properties should subscribe dependencies", () => { | ||
let cell = new SrcJsonCell({a: {b: {c: 2, d: 3}}, e: 1}); | ||
let x = bind(() => cell.snapGet('a.b').c); | ||
let spy = jasmine.createSpy('listener'); | ||
rx.autoSub(x.onSet, rx.skipFirst(spy)); | ||
expect(x.raw()).toBe(2); | ||
cell.data.a.b.d = 4; | ||
expect(spy).not.toHaveBeenCalled(); | ||
cell.data.a.b.c = 3; | ||
expect(x.raw()).toBe(3); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
it("", () => { | ||
}); | ||
}); |
@@ -261,2 +261,5 @@ import _ from 'underscore'; | ||
} | ||
snapGet(path) { | ||
return rx.snap(() => deepGet(this.data, path)); | ||
} | ||
} | ||
@@ -263,0 +266,0 @@ |
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
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
80519
-58.43%15
-11.76%1037
-74.88%- Removed