@schoolbelle/common
Version:
Demo library to showcase Angular packaging format
2 lines • 5.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("immutable"),require("lodash"),require("rxjs")):"function"==typeof define&&define.amd?define("@schoolbelle/common/services/object-change-tracker",["exports","immutable","lodash","rxjs"],e):e((t.schoolbelle=t.schoolbelle||{},t.schoolbelle.common=t.schoolbelle.common||{},t.schoolbelle.common.services=t.schoolbelle.common.services||{},t.schoolbelle.common.services["object-change-tracker"]={}),null,null,t.rxjs)}(this,function(t,i,s,o){"use strict";var n=function(){function t(t,e){void 0===t&&(t=undefined),void 0===e&&(e=[]),this.contentUpdateEvent=new o.BehaviorSubject([null,null]),this.root=t,this.pathsFromRoot=e}return Object.defineProperty(t.prototype,"onContentUpdate",{get:function(){return this.contentUpdateEvent.asObservable()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Immutable",{get:function(){return this.root?this.root.Immutable.getIn(this.pathsFromRoot):undefined},enumerable:!0,configurable:!0}),t.prototype.val=function(){return this.get([])},Object.defineProperty(t.prototype,"isChanged",{get:function(){return this.to&&"object"==typeof this.to&&0!==Object.keys(this.to).length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"origin",{get:function(){return s.get(this.root.origin,this.pathsFromRoot)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"to",{get:function(){return s.get(this.root.to,this.pathsFromRoot)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"from",{get:function(){return s.get(this.root.from,this.pathsFromRoot)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this.root.child(this.pathsFromRoot.slice(0,-1))},enumerable:!0,configurable:!0}),t.prototype.child=function(t){return this.root.child(this.pathsFromRoot.concat(t))},t.prototype.empty=function(){this.set([],null)},t.prototype.get=function(t){return t=this.pathsFromRoot.concat(t),this.root.get(t)},t.prototype.set=function(t,e){t=this.pathsFromRoot.concat(t),this.root.set(t,e)},t.prototype.destroy=function(){this.root.destroyChild(this.pathsFromRoot)},t}(),e=function(){function t(){this.contentUpdateEvent=new o.BehaviorSubject(null),this.data=i.fromJS({}),this.origin={},this.to={},this.from={},this.children=new Map}return Object.defineProperty(t.prototype,"onContentUpdate",{get:function(){return this.contentUpdateEvent.asObservable()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Immutable",{get:function(){return this.data},enumerable:!0,configurable:!0}),t.prototype.val=function(){return this.data.toJS()},Object.defineProperty(t.prototype,"isChanged",{get:function(){return 0!==Object.keys(this.to).length||0!==Object.keys(this.from).length},enumerable:!0,configurable:!0}),t.prototype.load=function(t){var o=this;this.data=i.fromJS(t),this.origin=Object.assign({},t),this.to={},this.from={},Array.from(this.children.keys()).sort(function(t,e){return t.length>e.length?1:t.length<e.length?-1:0}).forEach(function(t){var e=o.children.get(t);e&&e.contentUpdateEvent.next([e.to,e.from])}),this.contentUpdateEvent.next([this.to,this.from])},t.prototype.empty=function(){var o=this;this.data=i.fromJS({}),this.origin=Object.assign({}),this.to={},this.from={},Array.from(this.children.keys()).sort(function(t,e){return t.length>e.length?1:t.length<e.length?-1:0}).forEach(function(t){var e=o.children.get(t);e&&e.contentUpdateEvent.next([e.to,e.from])}),this.contentUpdateEvent.next([this.to,this.from])},t.prototype.backToOrigin=function(){var o=this;this.data=i.fromJS(this.origin),this.to={},this.from={},Array.from(this.children.keys()).sort(function(t,e){return t.length>e.length?1:t.length<e.length?-1:0}).forEach(function(t){var e=o.children.get(t);e&&e.contentUpdateEvent.next([e.to,e.from])}),this.contentUpdateEvent.next([this.to,this.from])},t.prototype.get=function(t){var e=this.data.getIn(t);return e&&"object"==typeof e&&(e=e.toJS()),e},t.prototype.set=function(n,t){var r=this;if(this.get(n)===t)return!1;var e=s.get(this.origin,n);return s.isEqual(e,t)?(s.unset(this.to,n),s.unset(this.from,n)):(s.set(this.to,n,"object"==typeof t?Object.assign({},t):t),s.set(this.from,n,e)),this.clean(this.to),this.clean(this.from),t&&"object"==typeof t&&(t=i.fromJS(t)),this.data=null===t?this.data.removeIn(n):this.data.setIn(n,t),n.forEach(function(t,e){var o=r.children.get(n.slice(0,n.length-e).join("/"));o&&o.contentUpdateEvent.next([o.to,o.from])}),this.contentUpdateEvent.next([this.to,this.from]),!0},t.prototype.clean=function(o){var n=this;o&&"object"==typeof o&&s.forEach(o,function(t,e){t&&"object"==typeof t?(n.clean(t),0===Object.keys(t).length&&delete o[e]):t!==undefined&&null!==t||delete o[e]})},t.prototype.child=function(t){if(0===t.length)return this;var e=this.children.get(t.join("/"));return e||(e=new n(this,t),this.children.set(t.join("/"),e)),e},t.prototype.destroyChild=function(t){this.children["delete"](t.join("/"))},t}();t.ObjectChangeChildTracker=n,t.ObjectChangeTracker=e,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=schoolbelle-common-services-object-change-tracker.umd.min.js.map