diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c8b455..6568a4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v2.5.2 + +* Fixing the library's export. + ## v2.5.1 * Fixing issue related to monkey not firing the correct events ([@roark](https://github.com/roark)). diff --git a/bower.json b/bower.json index c2450a2..99ce889 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "baobab", "main": "build/baobab.min.js", - "version": "2.5.0", + "version": "2.5.2", "homepage": "https://github.com/Yomguithereal/baobab", "author": { "name": "Guillaume Plique", diff --git a/build/baobab.js b/build/baobab.js index ac3545e..461e99c 100644 --- a/build/baobab.js +++ b/build/baobab.js @@ -2,7 +2,7 @@ * Baobab * * Homepage: https://github.com/Yomguithereal/baobab - * Version: 2.5.1 + * Version: 2.5.2 * Author: Yomguithereal (Guillaume Plique) * License: MIT */ @@ -564,8 +564,6 @@ },{}],2:[function(require,module,exports){ 'use strict'; -exports.__esModule = true; - var _emmett = require('emmett'); var _emmett2 = _interopRequireDefault(_emmett); @@ -1130,7 +1128,6 @@ var Baobab = function (_Emitter) { */ -exports.default = Baobab; Baobab.monkey = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; @@ -1154,9 +1151,14 @@ Baobab.type = _type2.default; Baobab.helpers = helpers; /** - * Version + * Version. + */ +Baobab.VERSION = '2.5.2'; + +/** + * Exporting. */ -Baobab.VERSION = '2.5.0'; +module.exports = Baobab; },{"./cursor":3,"./helpers":4,"./monkey":5,"./type":6,"./update":7,"./watcher":8,"emmett":1}],3:[function(require,module,exports){ 'use strict'; diff --git a/build/baobab.min.js b/build/baobab.min.js index ecf88da..c787f5f 100644 --- a/build/baobab.min.js +++ b/build/baobab.min.js @@ -2,8 +2,8 @@ * Baobab * * Homepage: https://github.com/Yomguithereal/baobab - * Version: 2.5.1 + * Version: 2.5.2 * Author: Yomguithereal (Guillaume Plique) * License: MIT */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Baobab=t()}}(function(){return function t(e,n,r){function o(a,s){if(!n[a]){if(!e[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var h=n[a]={exports:{}};e[a][0].call(h.exports,function(t){var n=e[a][1][t];return o(n||t)},h,h.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a1?t[e]=function(t,e){var n,r={};for(n in t)r[n]=t[n];for(n in e)r[n]=e[n];return r}(t[e],{once:!0}):t.push({once:!0}),this.on.apply(this,t)},a.prototype.off=function(t,e){var n,r,a,l;if(1===arguments.length&&"function"==typeof t){for(a in e=arguments[0],this._handlers)this._handlers[a]=s(this._handlers[a],e),0===this._handlers[a].length&&delete this._handlers[a];this._handlersAll=s(this._handlersAll,e),this._handlersComplex=s(this._handlersComplex,e)}else if(1!==arguments.length||"string"!=typeof t&&"symbol"!=typeof t)if(2===arguments.length){var u=[].concat(t);for(n=0,r=u.length;n1&&(n.data=e),s.fn.call("scope"in s?s.scope:this,n),s.once&&p.push(s);for(u=p.length-1;u>=0;u--)(r=p[u].type?this._handlers[p[u].type]:p[u].pattern?this._handlersComplex:this._handlersAll).splice(r.indexOf(p[u]),1)}return this},a.prototype.kill=function(){this.unbindAll(),this._handlers=null,this._handlersAll=null,this._handlersComplex=null,this._enabled=!1,this.unbindAll=this.on=this.once=this.off=this.emit=this.listeners=Function.prototype},a.prototype.disable=function(){return this._enabled=!1,this},a.prototype.enable=function(){return this._enabled=!0,this},a.version="3.1.1",void 0!==n?(void 0!==e&&e.exports&&(n=e.exports=a),n.Emitter=a):this.Emitter=a}).call(this)},{}],2:[function(t,e,n){"use strict";n.__esModule=!0;var r=h(t("emmett")),o=h(t("./cursor")),i=t("./monkey"),a=h(t("./watcher")),s=h(t("./type")),l=h(t("./update")),u=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}}(t("./helpers"));function h(t){return t&&t.__esModule?t:{default:t}}var f=u.arrayFrom,c=u.coercePath,p=u.deepFreeze,d=u.getIn,y=u.makeError,v=u.deepClone,m=u.deepMerge,b=u.shallowClone,g=u.shallowMerge,_=u.hashPath,w={autoCommit:!0,asynchronous:!0,immutable:!0,lazyMonkeys:!0,monkeyBusiness:!0,persistent:!0,pure:!0,validate:null,validationBehavior:"rollback"},k=function(t){function e(n,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=function(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}(this,t.call(this));if(arguments.length<1&&(n={}),!s.default.object(n)&&!s.default.array(n))throw y("Baobab: invalid data.",{data:n});i.options=g({},w,r),i.options.persistent||(i.options.immutable=!1,i.options.pure=!1),i._identity="[object Baobab]",i._cursors={},i._future=null,i._transaction=[],i._affectedPathsIndex={},i._monkeys={},i._previousData=null,i._data=n,i.root=new o.default(i,[],"λ"),delete i.root.release,i.options.immutable&&p(i._data);["apply","clone","concat","deepClone","deepMerge","exists","get","push","merge","pop","project","serialize","set","shift","splice","unset","unshift"].forEach(function(t){i[t]=function(){var e=this.root[t].apply(this.root,arguments);return e instanceof o.default?this:e}}),i.options.monkeyBusiness&&i._refreshMonkeys();var a=i.validate();if(a)throw Error("Baobab: invalid data.",{error:a});return i}return function(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)}(e,t),e.prototype._refreshMonkeys=function(t,e,n){var r=this,o=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(e instanceof i.MonkeyDefinition||e instanceof i.Monkey){var o=new i.Monkey(r,n,e instanceof i.Monkey?e.definition:e);(0,l.default)(r._monkeys,n,{type:"set",value:o},{immutable:!1,persistent:!1,pure:!1})}else if(s.default.object(e))for(var a in e)t(e[a],n.concat(a))};if(arguments.length){var a=d(this._monkeys,e).data;a&&function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(e instanceof i.Monkey)return e.release(),void(0,l.default)(r._monkeys,n,{type:"unset"},{immutable:!1,persistent:!1,pure:!1});if(s.default.object(e))for(var o in e)t(e[o],n.concat(o))}(a,e),"unset"!==n&&o(t,e)}else o(this._data);return this},e.prototype.validate=function(t){var e=this.options,n=e.validate,r=e.validationBehavior;if("function"!=typeof n)return null;var o=n.call(this,this._previousData,this._data,t||[[]]);return o instanceof Error?("rollback"===r&&(this._data=this._previousData,this._affectedPathsIndex={},this._transaction=[],this._previousData=this._data),this.emit("invalid",{error:o}),o):null},e.prototype.select=function(t){if(t=t||[],arguments.length>1&&(t=f(arguments)),!s.default.path(t))throw y("Baobab.select: invalid path.",{path:t});t=[].concat(t);var e=_(t),n=this._cursors[e];return n||(n=new o.default(this,t,e),this._cursors[e]=n),this.emit("select",{path:t,cursor:n}),n},e.prototype.update=function(t,e){var n=this;if(t=c(t),!s.default.operationType(e.type))throw y('Baobab.update: unknown operation type "'+e.type+'".',{operation:e});var r=d(this._data,t),o=r.solvedPath,i=r.exists;if(!o)throw y("Baobab.update: could not solve the given path.",{path:o});var a=s.default.monkeyPath(this._monkeys,o);if(a&&o.length>a.length)throw y("Baobab.update: attempting to update a read-only path.",{path:o});if("unset"!==e.type||i){var u=e;if(/merge/i.test(e.type)){var h=d(this._monkeys,o).data;if(s.default.object(h)){u=b(u);var f=d(this._data,o).data;/deep/i.test(u.type)?u.value=m({},m({},f,v(h)),u.value):u.value=g({},m({},f,v(h)),u.value)}}this._transaction.length||(this._previousData=this._data);var p=(0,l.default)(this._data,o,u,this.options),w=p.data,k=p.node;if(!("data"in p))return k;var P=o.concat("push"===e.type?k.length-1:[]),j=_(P);return this._data=w,this._affectedPathsIndex[j]=!0,this._transaction.push(g({},e,{path:P})),this.options.monkeyBusiness&&this._refreshMonkeys(k,o,e.type),this.emit("write",{path:P}),this.options.autoCommit?this.options.asynchronous?(this._future||(this._future=setTimeout(function(){return n.commit()},0)),k):(this.commit(),k):k}},e.prototype.commit=function(){if(!this._transaction.length)return this;this._future&&(this._future=clearTimeout(this._future));var t=Object.keys(this._affectedPathsIndex).map(function(t){return"λ"!==t?t.split("λ").slice(1):[]});if(this.validate(t))return this;var e=this._transaction,n=this._previousData;return this._affectedPathsIndex={},this._transaction=[],this._previousData=this._data,this.emit("update",{paths:t,currentData:this._data,transaction:e,previousData:n}),this},e.prototype.getMonkey=function(t){t=c(t);var e=d(this._monkeys,[].concat(t)).data;return e instanceof i.Monkey?e:null},e.prototype.watch=function(t){return new a.default(this,t)},e.prototype.release=function(){var t=void 0;for(t in this.emit("release"),delete this.root,delete this._data,delete this._previousData,delete this._transaction,delete this._affectedPathsIndex,delete this._monkeys,this._cursors)this._cursors[t].release();delete this._cursors,this.kill()},e.prototype.toJSON=function(){return this.serialize()},e.prototype.toString=function(){return this._identity},e}(r.default);n.default=k,k.monkey=function(){for(var t=arguments.length,e=Array(t),n=0;n1&&(t=(0,a.arrayFrom)(arguments)),this.tree.select(this.path.concat(t))},e.prototype.up=function(){return this.isRoot()?null:this.tree.select(this.path.slice(0,-1))},e.prototype.down=function(){if(l("down",this.solvedPath),!(this._get().data instanceof Array))throw Error("Baobab.Cursor.down: cannot go down on a non-list type.");return this.tree.select(this.solvedPath.concat(0))},e.prototype.left=function(){l("left",this.solvedPath);var t=+this.solvedPath[this.solvedPath.length-1];if(isNaN(t))throw Error("Baobab.Cursor.left: cannot go left on a non-list type.");return t?this.tree.select(this.solvedPath.slice(0,-1).concat(t-1)):null},e.prototype.right=function(){l("right",this.solvedPath);var t=+this.solvedPath[this.solvedPath.length-1];if(isNaN(t))throw Error("Baobab.Cursor.right: cannot go right on a non-list type.");return t+1===this.up()._get().data.length?null:this.tree.select(this.solvedPath.slice(0,-1).concat(t+1))},e.prototype.leftmost=function(){l("leftmost",this.solvedPath);var t=+this.solvedPath[this.solvedPath.length-1];if(isNaN(t))throw Error("Baobab.Cursor.leftmost: cannot go left on a non-list type.");return this.tree.select(this.solvedPath.slice(0,-1).concat(0))},e.prototype.rightmost=function(){l("rightmost",this.solvedPath);var t=+this.solvedPath[this.solvedPath.length-1];if(isNaN(t))throw Error("Baobab.Cursor.rightmost: cannot go right on a non-list type.");var e=this.up()._get().data;return this.tree.select(this.solvedPath.slice(0,-1).concat(e.length-1))},e.prototype.map=function(t,e){l("map",this.solvedPath);var n=this._get().data,r=arguments.length;if(!i.default.array(n))throw Error("baobab.Cursor.map: cannot map a non-list type.");return n.map(function(o,i){return t.call(r>1?e:this,this.select(i),i,n)},this)},e.prototype._get=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!i.default.path(t))throw(0,a.makeError)("Baobab.Cursor.getters: invalid path.",{path:t});return this.solvedPath?(0,a.getIn)(this.tree._data,this.solvedPath.concat(t)):{data:void 0,solvedPath:null,exists:!1}},e.prototype.exists=function(t){return t=(0,a.coercePath)(t),arguments.length>1&&(t=(0,a.arrayFrom)(arguments)),this._get(t).exists},e.prototype.get=function(t){t=(0,a.coercePath)(t),arguments.length>1&&(t=(0,a.arrayFrom)(arguments));var e=this._get(t),n=e.data,r=e.solvedPath;return this.tree.emit("get",{data:n,solvedPath:r,path:this.path.concat(t)}),n},e.prototype.clone=function(){var t=this.get.apply(this,arguments);return(0,a.shallowClone)(t)},e.prototype.deepClone=function(){var t=this.get.apply(this,arguments);return(0,a.deepClone)(t)},e.prototype.serialize=function(t){if(t=(0,a.coercePath)(t),arguments.length>1&&(t=(0,a.arrayFrom)(arguments)),!i.default.path(t))throw(0,a.makeError)("Baobab.Cursor.getters: invalid path.",{path:t});if(this.solvedPath){var e=this.solvedPath.concat(t),n=(0,a.deepClone)((0,a.getIn)(this.tree._data,e).data);return function t(e,n){if(i.default.object(n)&&i.default.object(e))for(var r in n)n[r]instanceof o.Monkey?delete e[r]:t(e[r],n[r])}(n,(0,a.getIn)(this.tree._monkeys,e).data),n}},e.prototype.project=function(t){if(i.default.object(t)){var e={};for(var n in t)e[n]=this.get(t[n]);return e}if(i.default.array(t)){for(var r=[],o=0,s=t.length;o0&&void 0!==arguments[0]?arguments[0]:1;if(!this.state.recording)throw new Error("Baobab.Cursor.undo: cursor is not recording.");var e=this.archive.back(t);if(!e)throw Error("Baobab.Cursor.undo: cannot find a relevant record.");return this.state.undoing=!0,this.set(e),this},e.prototype.hasHistory=function(){return!(!this.archive||!this.archive.get().length)},e.prototype.getHistory=function(){return this.archive?this.archive.get():[]},e.prototype.clearHistory=function(){return this.archive&&this.archive.clear(),this},e.prototype.release=function(){this._dynamicPath&&this.tree.off("write",this._writeHandler),this.tree.off("update",this._updateHandler),this.hash&&delete this.tree._cursors[this.hash],delete this.tree,delete this.path,delete this.solvedPath,delete this.archive,this.kill(),this.state.killed=!0},e.prototype.toJSON=function(){return this.serialize()},e.prototype.toString=function(){return this._identity},e}(r.default);n.default=u,"function"==typeof Symbol&&void 0!==Symbol.iterator&&(u.prototype[Symbol.iterator]=function(){var t=this._get().data;if(!i.default.array(t))throw Error("baobab.Cursor.@@iterate: cannot iterate a non-list type.");var e=0,n=this,r=t.length;return{next:function(){return e2)throw(0,a.makeError)("Baobab.Cursor."+t+": too many arguments.");if(1!==arguments.length||h[t]||(r=n,n=[]),n=(0,a.coercePath)(n),!i.default.path(n))throw(0,a.makeError)("Baobab.Cursor."+t+": invalid path.",{path:n});if(e&&!e(r))throw(0,a.makeError)("Baobab.Cursor."+t+": invalid value.",{path:n,value:r});if(!this.solvedPath)throw(0,a.makeError)("Baobab.Cursor."+t+": the dynamic path of the cursor cannot be solved.",{path:this.path});var o=this.solvedPath.concat(n);return this.tree.update(o,{type:t,value:r})}}f("set"),f("unset"),f("apply",i.default.function),f("push"),f("concat",i.default.array),f("unshift"),f("pop"),f("shift"),f("splice",i.default.splicer),f("merge",i.default.object),f("deepMerge",i.default.object)},{"./helpers":4,"./monkey":5,"./type":6,emmett:1}],4:[function(t,e,n){(function(e){"use strict";n.__esModule=!0,n.uniqid=n.deepMerge=n.shallowMerge=n.deepFreeze=n.freeze=n.deepClone=n.shallowClone=n.Archive=void 0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};n.arrayFrom=function(t){return h(t)},n.before=function(t,e){return function(){t.apply(null,arguments),e.apply(null,arguments)}},n.coercePath=function(t){return t||0===t||""===t?t:[]},n.getIn=function(t,e){if(!e)return b;var n=[],o=!0,i=t,a=void 0,l=void 0,h=void 0;for(l=0,h=e.length;l3?r-3:0),i=3;i=0?t.slice(0,e).concat(o).concat(t.slice(e+n)):t.slice(0,t.length+e).concat(o).concat(t.slice(t.length+e+n))};var o,i=t("./monkey"),a=t("./type"),s=(o=a)&&o.__esModule?o:{default:o};var l={}.hasOwnProperty;function u(t,e){var n,r=void 0;for(r=0,n=t.length;rthis.size&&(this.records.length=this.size),this},t.prototype.clear=function(){return this.records=[],this},t.prototype.back=function(t){var e=this.records[t-1];return e&&(this.records=this.records.slice(t)),e},t}();function f(t,n){if(!n||"object"!==(void 0===n?"undefined":r(n))||n instanceof Error||n instanceof i.MonkeyDefinition||n instanceof i.Monkey||"ArrayBuffer"in e&&n instanceof ArrayBuffer)return n;if(s.default.array(n)){if(t){for(var o=new Array(n.length),a=0,l=n.length;a1?e-1:0),r=1;r0&&void 0!==arguments[0])||arguments[0],n=void 0;return n=this.definition.hasDynamicPaths?this.depPaths.map(function(e){return(0,i.getIn)(t.tree._data,e).solvedPath}):this.depPaths,e&&this.depPaths.some(function(e){return!!r.default.monkeyPath(t.tree._monkeys,e)})?n.reduce(function(e,n){var o=r.default.monkeyPath(t.tree._monkeys,n);if(!o)return e.concat([n]);var a=(0,i.getIn)(t.tree._monkeys,o).data;return e.concat(a.relatedPaths())},[]):n},t.prototype.update=function(){var t,e,n,r,a,s=this,l=this.tree.project(this.projection),u=(t=this.tree,e=this.definition,n=l,r=null,a=!1,function(){if(!a){r=e.getter.apply(t,"object"===e.type?[n]:n),t.options.immutable&&!1!==e.options.immutable&&(0,i.deepFreeze)(r);var o=(0,i.hashPath)(s.path);t._affectedPathsIndex[o]=!0,a=!0}return r});if(u.isLazyGetter=!0,this.tree.options.lazyMonkeys)this.tree._data=(0,o.default)(this.tree._data,this.path,{type:"monkey",value:u},this.tree.options).data;else{var h=(0,o.default)(this.tree._data,this.path,{type:"set",value:u(),options:{mutableLeaf:!this.definition.options.immutable}},this.tree.options);"data"in h&&(this.tree._data=h.data)}return this.tree.emit("_monkey",{monkey:this,path:this.path}),this},t.prototype.release=function(){this.tree.off("write",this.writeListener),this.tree.off("_monkey",this.recursiveListener),this.state.killed=!0,delete this.projection,delete this.depPaths,delete this.tree},t}()},{"./helpers":4,"./type":6,"./update":7}],6:[function(t,e,n){"use strict";n.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=t("./monkey"),i={};function a(t,e){return e.some(function(e){return i[e](t)})}i.array=function(t){return Array.isArray(t)},i.object=function(t){return t&&"object"===(void 0===t?"undefined":r(t))&&!Array.isArray(t)&&!(t instanceof Date)&&!(t instanceof RegExp)&&!("function"==typeof Map&&t instanceof Map)&&!("function"==typeof Set&&t instanceof Set)},i.string=function(t){return"string"==typeof t},i.number=function(t){return"number"==typeof t},i.function=function(t){return"function"==typeof t},i.primitive=function(t){return t!==Object(t)},i.splicer=function(t){return!(!i.array(t)||t.length<1)&&(!(t.length>1&&isNaN(+t[1]))&&a(t[0],["number","function","object"]))};var s=["string","number","function","object"];i.path=function(t){return!(!t&&0!==t&&""!==t)&&[].concat(t).every(function(t){return a(t,s)})},i.dynamicPath=function(t){return t.some(function(t){return i.function(t)||i.object(t)})},i.monkeyPath=function(t,e){var n,i=[],a=t,s=void 0;for(s=0,n=e.length;s3&&void 0!==arguments[3]?arguments[3]:{},o=n.type,l=n.value,u=n.options,h=void 0===u?{}:u,f={root:t},c=["root"].concat(e),p=[],d=f,y=void 0,v=void 0,m=void 0;for(y=0,v=c.length;y0&&p.push(m),y===v-1){if("set"===o){if(r.pure&&d[m]===l)return{node:d[m]};i.default.lazyGetter(d,m)?Object.defineProperty(d,m,{value:l,enumerable:!0,configurable:!0}):r.persistent&&!h.mutableLeaf?d[m]=(0,a.shallowClone)(l):d[m]=l}else if("monkey"===o)Object.defineProperty(d,m,{get:l,enumerable:!0,configurable:!0});else if("apply"===o){var b=l(d[m]);if(r.pure&&d[m]===b)return{node:d[m]};i.default.lazyGetter(d,m)?Object.defineProperty(d,m,{value:b,enumerable:!0,configurable:!0}):r.persistent?d[m]=(0,a.shallowClone)(b):d[m]=b}else if("push"===o){if(!i.default.array(d[m]))throw s("push","array",p);r.persistent?d[m]=d[m].concat([l]):d[m].push(l)}else if("unshift"===o){if(!i.default.array(d[m]))throw s("unshift","array",p);r.persistent?d[m]=[l].concat(d[m]):d[m].unshift(l)}else if("concat"===o){if(!i.default.array(d[m]))throw s("concat","array",p);r.persistent?d[m]=d[m].concat(l):d[m].push.apply(d[m],l)}else if("splice"===o){if(!i.default.array(d[m]))throw s("splice","array",p);r.persistent?d[m]=a.splice.apply(null,[d[m]].concat(l)):d[m].splice.apply(d[m],l)}else if("pop"===o){if(!i.default.array(d[m]))throw s("pop","array",p);r.persistent?d[m]=(0,a.splice)(d[m],-1,1):d[m].pop()}else if("shift"===o){if(!i.default.array(d[m]))throw s("shift","array",p);r.persistent?d[m]=(0,a.splice)(d[m],0,1):d[m].shift()}else if("unset"===o)i.default.object(d)?delete d[m]:i.default.array(d)&&d.splice(m,1);else if("merge"===o){if(!i.default.object(d[m]))throw s("merge","object",p);r.persistent?d[m]=(0,a.shallowMerge)({},d[m],l):d[m]=(0,a.shallowMerge)(d[m],l)}else if("deepMerge"===o){if(!i.default.object(d[m]))throw s("deepMerge","object",p);r.persistent?d[m]=(0,a.deepMerge)({},d[m],l):d[m]=(0,a.deepMerge)(d[m],l)}r.immutable&&!h.mutableLeaf&&(0,a.deepFreeze)(d);break}i.default.primitive(d[m])?d[m]={}:r.persistent&&(d[m]=(0,a.shallowClone)(d[m])),r.immutable&&v>0&&(0,a.freeze)(d),d=d[m]}return i.default.lazyGetter(d,m)?{data:f.root}:{data:f.root,node:d[m]}};var r,o=t("./type"),i=(r=o)&&r.__esModule?r:{default:r},a=t("./helpers");function s(t,e,n){return(0,a.makeError)('Baobab.update: cannot apply the "'+t+'" on a non '+e+" (path: /"+n.join("/")+").",{path:n})}},{"./helpers":4,"./type":6}],8:[function(t,e,n){"use strict";n.__esModule=!0;var r=s(t("emmett")),o=s(t("./cursor")),i=s(t("./type")),a=t("./helpers");function s(t){return t&&t.__esModule?t:{default:t}}var l=function(t){function e(n,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(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}(this,t.call(this));return o.tree=n,o.mapping=null,o.state={killed:!1},o.refresh(r),o.handler=function(t){if(!o.state.killed){var e=o.getWatchedPaths();return(0,a.solveUpdate)(t.data.paths,e)?o.emit("update"):void 0}},o.tree.on("update",o.handler),o}return function(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)}(e,t),e.prototype.getWatchedPaths=function(){var t=this;return Object.keys(this.mapping).map(function(e){var n=t.mapping[e];return n instanceof o.default?n.solvedPath:t.mapping[e]}).reduce(function(e,n){if(n=[].concat(n),i.default.dynamicPath(n)&&(n=(0,a.getIn)(t.tree._data,n).solvedPath),!n)return e;var r=i.default.monkeyPath(t.tree._monkeys,n);return r?e.concat((0,a.getIn)(t.tree._monkeys,r).data.relatedPaths()):e.concat([n])},[])},e.prototype.getCursors=function(){var t=this,e={};return Object.keys(this.mapping).forEach(function(n){var r=t.mapping[n];r instanceof o.default?e[n]=r:e[n]=t.tree.select(r)}),e},e.prototype.refresh=function(t){if(!i.default.watcherMapping(t))throw(0,a.makeError)("Baobab.watch: invalid mapping.",{mapping:t});this.mapping=t;var e={};for(var n in t)e[n]=t[n]instanceof o.default?t[n].path:t[n];this.get=this.tree.project.bind(this.tree,e)},e.prototype.release=function(){this.tree.off("update",this.handler),this.state.killed=!0,this.kill()},e}(r.default);n.default=l},{"./cursor":3,"./helpers":4,"./type":6,emmett:1}]},{},[2])(2)}); \ No newline at end of file +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Baobab=t()}}(function(){return function i(a,s,l){function u(n,t){if(!s[n]){if(!a[n]){var e="function"==typeof require&&require;if(!t&&e)return e(n,!0);if(h)return h(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var o=s[n]={exports:{}};a[n][0].call(o.exports,function(t){var e=a[n][1][t];return u(e||t)},o,o.exports,i,a,s,l)}return s[n].exports}for(var h="function"==typeof require&&require,t=0;ta.length)throw g("Baobab.update: attempting to update a read-only path.",{path:o});if("unset"!==e.type||i){var s=e;if(/merge/i.test(e.type)){var l=b(this._monkeys,o).data;if(y.default.object(l)){s=k(s);var u=b(this._data,o).data;/deep/i.test(s.type)?s.value=w({},w({},u,_(l)),s.value):s.value=P({},w({},u,_(l)),s.value)}}this._transaction.length||(this._previousData=this._data);var h=(0,v.default)(this._data,o,s,this.options),f=h.data,c=h.node;if(!("data"in h))return c;var p=o.concat("push"===e.type?c.length-1:[]),d=j(p);return this._data=f,this._affectedPathsIndex[d]=!0,this._transaction.push(P({},e,{path:p})),this.options.monkeyBusiness&&this._refreshMonkeys(c,o,e.type),this.emit("write",{path:p}),this.options.autoCommit?(this.options.asynchronous?this._future||(this._future=setTimeout(function(){return n.commit()},0)):this.commit(),c):c}},i.prototype.commit=function(){if(!this._transaction.length)return this;this._future&&(this._future=clearTimeout(this._future));var t=Object.keys(this._affectedPathsIndex).map(function(t){return"λ"!==t?t.split("λ").slice(1):[]});if(this.validate(t))return this;var e=this._transaction,n=this._previousData;return this._affectedPathsIndex={},this._transaction=[],this._previousData=this._data,this.emit("update",{paths:t,currentData:this._data,transaction:e,previousData:n}),this},i.prototype.getMonkey=function(t){t=m(t);var e=b(this._monkeys,[].concat(t)).data;return e instanceof s.Monkey?e:null},i.prototype.watch=function(t){return new l.default(this,t)},i.prototype.release=function(){var t=void 0;for(t in this.emit("release"),delete this.root,delete this._data,delete this._previousData,delete this._transaction,delete this._affectedPathsIndex,delete this._monkeys,this._cursors)this._cursors[t].release();delete this._cursors,this.kill()},i.prototype.toJSON=function(){return this.serialize()},i.prototype.toString=function(){return this._identity},i}(r.default);c.monkey=function(){for(var t=arguments.length,e=Array(t),n=0;nthis.size&&(this.records.length=this.size),this},e.prototype.clear=function(){return this.records=[],this},e.prototype.back=function(t){var e=this.records[t-1];return e&&(this.records=this.records.slice(t)),e},e}();function g(t,e){if(!e||"object"!==(void 0===e?"undefined":y(e))||e instanceof Error||e instanceof v.MonkeyDefinition||e instanceof v.Monkey||"ArrayBuffer"in d&&e instanceof ArrayBuffer)return e;if(m.default.array(e)){if(t){for(var n=new Array(e.length),r=0,o=e.length;r