From f1867a39d143ba3ec3f1f2d651f09f49cbcb92f4 Mon Sep 17 00:00:00 2001 From: Yomguithereal Date: Fri, 11 Dec 2015 14:17:50 +0100 Subject: [PATCH] Bump 2.2.0 --- CHANGELOG.md | 3 ++- bower.json | 2 +- build/baobab.js | 4 ++-- build/baobab.min.js | 4 ++-- package.json | 2 +- src/baobab.js | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0ae68..4e87abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog -## v2.2.0 (provisional) +## v2.2.0 * Cursors are now ES6 iterables ([@kirjs](https://github.com/kirjs)). +* Dropping the `.babelrc` file from the npm build. ## v2.1.2 diff --git a/bower.json b/bower.json index 8c16ee9..46e6dc0 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "baobab", "main": "build/baobab.min.js", - "version": "2.1.2", + "version": "2.2.0", "homepage": "https://github.com/Yomguithereal/baobab", "author": { "name": "Guillaume Plique", diff --git a/build/baobab.js b/build/baobab.js index 0c03ec4..fd80548 100644 --- a/build/baobab.js +++ b/build/baobab.js @@ -1,4 +1,4 @@ -/* baobab.js - Version: 2.1.2 - Author: Yomguithereal (Guillaume Plique) */ +/* baobab.js - Version: 2.2.0 - Author: Yomguithereal (Guillaume Plique) */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Baobab = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;oo;o++)e.call(r||null,n[o],t[n[o]])}function a(t,e){t=t||[];var r,n,i=[];for(n=0,r=t.length;r>n;n++)t[n].fn!==e&&i.push(t[n]);return i}var s={once:"boolean",scope:"object"},u=0,h=function(){this._enabled=!0,this.unbindAll()};h.prototype.unbindAll=function(){return this._handlers={},this._handlersAll=[],this._handlersComplex=[],this},h.prototype.on=function(t,e,r){var n,a,h,l,f,c,p;if(i(t))return o(t,function(t,r){this.on(t,r,e)},this),this;for("function"==typeof t&&(r=e,e=t,t=null),f=[].concat(t),n=0,a=f.length;a>n;n++){if(l=f[n],p={order:u++,fn:e},"string"==typeof l||"symbol"==typeof l)this._handlers[l]||(this._handlers[l]=[]),c=this._handlers[l],p.type=l;else if(l instanceof RegExp)c=this._handlersComplex,p.pattern=l;else{if(null!==l)throw Error("Emitter.on: invalid event.");c=this._handlersAll}for(h in r||{})s[h]&&(p[h]=r[h]);c.push(p)}return this},h.prototype.once=function(){var t=Array.prototype.slice.call(arguments),r=t.length-1;return i(t[r])&&t.length>1?t[r]=e(t[r],{once:!0}):t.push({once:!0}),this.on.apply(this,t)},h.prototype.off=function(t,e){var r,n,s,u;if(1===arguments.length&&"function"==typeof t){e=arguments[0];for(s in this._handlers)this._handlers[s]=a(this._handlers[s],e),0===this._handlers[s].length&&delete this._handlers[s];this._handlersAll=a(this._handlersAll,e),this._handlersComplex=a(this._handlersComplex,e)}else if(1!==arguments.length||"string"!=typeof t&&"symbol"!=typeof t)if(2===arguments.length){var h=[].concat(t);for(r=0,n=h.length;n>r;r++)u=h[r],this._handlers[u]=a(this._handlers[u],e),0===(this._handlers[u]||[]).length&&delete this._handlers[u]}else i(t)&&o(t,this.off,this);else delete this._handlers[t];return this},h.prototype.listeners=function(t){var e,r,n,i=this._handlersAll||[],o=!1;if(!t)throw Error("Emitter.listeners: no event provided.");for(i=i.concat(this._handlers[t]||[]),r=0,n=this._handlersComplex.length;n>r;r++)e=this._handlersComplex[r],~t.search(e.pattern)&&(o=!0,i.push(e));return this._handlersAll.length||o?i.sort(function(t,e){return t.order-e.order}):i.slice(0)},h.prototype.emit=function(t,e){if(!this._enabled)return this;if(i(t))return o(t,this.emit,this),this;var r,n,a,s,u,h,l,f,c=[].concat(t),p=[];for(u=0,l=c.length;l>u;u++){for(a=this.listeners(c[u]),h=0,f=a.length;f>h;h++)s=a[h],r={type:c[u],target:this},arguments.length>1&&(r.data=e),s.fn.call("scope"in s?s.scope:this,r),s.once&&p.push(s);for(h=p.length-1;h>=0;h--)n=p[h].type?this._handlers[p[h].type]:p[h].pattern?this._handlersComplex:this._handlersAll,n.splice(n.indexOf(p[h]),1)}return this},h.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},h.prototype.disable=function(){return this._enabled=!1,this},h.prototype.enable=function(){return this._enabled=!0,this},h.version="3.1.1","undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=h),n.Emitter=h):"function"==typeof t&&t.amd?t("emmett",[],function(){return h}):this.Emitter=h}).call(this)},{}],2:[function(t,e,r){"use strict";function n(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e["default"]=t,e}function i(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(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 s(t){return"λ"+t.map(function(t){return g["default"]["function"](t)||g["default"].object(t)?"#"+B()+"#":t}).join("λ")}r.__esModule=!0;var u=Object.assign||function(t){for(var e=1;e1&&(t=P(arguments)),!g["default"].path(t))throw O("Baobab.select: invalid path.",{path:t});t=[].concat(t);var e=s(t),r=this._cursors[e];return r||(r=new c["default"](this,t,e),this._cursors[e]=r),this.emit("select",{path:t,cursor:r}),r},e.prototype.update=function(t,e){var r=this;if(t=k(t),!g["default"].operationType(e.type))throw O('Baobab.update: unknown operation type "'+e.type+'".',{operation:e});var n=M(this._data,t),i=n.solvedPath,o=n.exists;if(!i)throw O("Baobab.update: could not solve the given path.",{path:i});var a=g["default"].monkeyPath(this._monkeys,i);if(a&&i.length>a.length)throw O("Baobab.update: attempting to update a read-only path.",{path:i});if("unset"!==e.type||o){var h=e;if(/merge/.test(e.type)){var l=M(this._monkeys,i).data;g["default"].object(l)&&(h=x(h),/deep/.test(h.type)?h.value=E({},l,h.value):h.value=C({},l,h.value))}this._transaction.length||(this._previousData=this._data);var f=b["default"](this._data,i,h,this.options),c=f.data,p=f.node;if(!("data"in f))return p;var d=i.concat("push"===e.type?p.length-1:[]),y=s(d);return this._data=c,this._affectedPathsIndex[y]=!0,this._transaction.push(u({},e,{path:d})),this._refreshMonkeys(p,i,e.type),this.emit("write",{path:d}),this.options.autoCommit?this.options.asynchronous?(this._future||(this._future=setTimeout(function(){return r.commit()},0)),p):(this.commit(),p):p}},e.prototype.commit=function(){this._future&&(this._future=clearTimeout(this._future));var t=Object.keys(this._affectedPathsIndex).map(function(t){return"λ"!==t?t.split("λ").slice(1):[]}),e=this.validate(t);if(e)return this;var r=this._transaction,n=this._previousData;return this._affectedPathsIndex={},this._transaction=[],this._previousData=this._data,this.emit("update",{paths:t,currentData:this._data,transaction:r,previousData:n}),this},e.prototype.watch=function(t){return new y["default"](this,t)},e.prototype.release=function(){var t=void 0;this.emit("release"),delete this.root,delete this._data,delete this._previousData,delete this._transaction,delete this._affectedPathsIndex,delete this._monkeys;for(t in 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}(l["default"]);r["default"]=z,z.monkey=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];if(!e.length)throw new Error("Baobab.monkey: missing definition.");return 1===e.length?new p.MonkeyDefinition(e[0]):new p.MonkeyDefinition(e)},z.dynamicNode=z.monkey,z.Cursor=c["default"],z.MonkeyDefinition=p.MonkeyDefinition,z.Monkey=p.Monkey,z.type=g["default"],z.helpers=w,Object.defineProperty(z,"version",{value:"2.1.2"}),r["default"]=z,e.exports=r["default"]},{"./cursor":3,"./helpers":4,"./monkey":5,"./type":6,"./update":7,"./watcher":8,emmett:1}],3:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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 a(t,e){if(!e)throw p.makeError("Baobab.Cursor."+t+": "+("cannot use "+t+" on an unresolved dynamic path."),{path:e})}function s(t,e){d.prototype[t]=function(r,n){if(arguments.length>2)throw p.makeError("Baobab.Cursor."+t+": too many arguments.");if(1===arguments.length&&"unset"!==t&&(n=r,r=[]),r=p.coercePath(r),!c["default"].path(r))throw p.makeError("Baobab.Cursor."+t+": invalid path.",{path:r});if(e&&!e(n))throw p.makeError("Baobab.Cursor."+t+": invalid value.",{path:r,value:n});var i=this.solvedPath.concat(r);return this.tree.update(i,{type:t,value:n})}}r.__esModule=!0;var u=t("emmett"),h=n(u),l=t("./monkey"),f=t("./type"),c=n(f),p=t("./helpers"),d=function(t){function e(r,n,o){var a=this;i(this,e),t.call(this),n=n||[],this._identity="[object Cursor]",this._archive=null,this.tree=r,this.path=n,this.hash=o,this.state={killed:!1,recording:!1,undoing:!1},this._dynamicPath=c["default"].dynamicPath(this.path),this._monkeyPath=c["default"].monkeyPath(this.tree._monkeys,this.path),this._dynamicPath?this.solvedPath=p.getIn(this.tree._data,this.path).solvedPath:this.solvedPath=this.path,this._writeHandler=function(t){var e=t.data;!a.state.killed&&p.solveUpdate([e.path],a._getComparedPaths())&&(a.solvedPath=p.getIn(a.tree._data,a.path).solvedPath)};var s=function(t){var e=a,r=Object.defineProperties({},{previousData:{get:function(){return p.getIn(t,e.solvedPath).data},configurable:!0,enumerable:!0},currentData:{get:function(){return e.get()},configurable:!0,enumerable:!0}});return a.state.recording&&!a.state.undoing&&a.archive.add(r.previousData),a.state.undoing=!1,a.emit("update",r)};this._updateHandler=function(t){if(!a.state.killed){var e=t.data,r=e.paths,n=e.previousData,i=s.bind(a,n),o=a._getComparedPaths();return p.solveUpdate(r,o)?i():void 0}};var u=!1;this._lazyBind=function(){return u?void 0:(u=!0,a._dynamicPath&&a.tree.on("write",a._writeHandler),a.tree.on("update",a._updateHandler))},this._dynamicPath?this._lazyBind():(this.on=p.before(this._lazyBind,this.on.bind(this)),this.once=p.before(this._lazyBind,this.once.bind(this)))}return o(e,t),e.prototype._getComparedPaths=function(){var t=this._monkeyPath?p.getIn(this.tree._monkeys,this._monkeyPath).data.relatedPaths():[];return[this.solvedPath].concat(t)},e.prototype.isRoot=function(){return!this.path.length},e.prototype.isLeaf=function(){return c["default"].primitive(this._get().data)},e.prototype.isBranch=function(){return!this.isRoot()&&!this.isLeaf()},e.prototype.root=function(){return this.tree.select()},e.prototype.select=function(t){return arguments.length>1&&(t=p.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(a("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(){a("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(){a("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(){a("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(){a("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){a("map",this.solvedPath);var r=this._get().data,n=arguments.length;if(!c["default"].array(r))throw Error("baobab.Cursor.map: cannot map a non-list type.");return r.map(function(i,o){return t.call(n>1?e:this,this.select(o),o,r)},this)},e.prototype._get=function(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];if(!c["default"].path(t))throw p.makeError("Baobab.Cursor.getters: invalid path.",{path:t});return this.solvedPath?p.getIn(this.tree._data,this.solvedPath.concat(t)):{data:void 0,solvedPath:null,exists:!1}},e.prototype.exists=function(t){return t=p.coercePath(t),arguments.length>1&&(t=p.arrayFrom(arguments)),this._get(t).exists},e.prototype.get=function(t){t=p.coercePath(t),arguments.length>1&&(t=p.arrayFrom(arguments));var e=this._get(t),r=e.data,n=e.solvedPath;return this.tree.emit("get",{data:r,solvedPath:n,path:this.path.concat(t)}),r},e.prototype.serialize=function(t){if(t=p.coercePath(t),arguments.length>1&&(t=p.arrayFrom(arguments)),!c["default"].path(t))throw p.makeError("Baobab.Cursor.getters: invalid path.",{path:t});if(this.solvedPath){var e=this.solvedPath.concat(t),r=p.deepClone(p.getIn(this.tree._data,e).data),n=p.getIn(this.tree._monkeys,e).data,i=function o(t,e){if(c["default"].object(e)&&c["default"].object(t))for(var r in e)e[r]instanceof l.Monkey?delete t[r]:o(t[r],e[r])};return i(r,n),r}},e.prototype.project=function(t){if(c["default"].object(t)){var e={};for(var r in t)e[r]=this.get(t[r]);return e}if(c["default"].array(t)){for(var e=[],n=0,i=t.length;i>n;n++)e.push(this.get(t[n]));return e}throw p.makeError("Baobab.Cursor.project: wrong projection.",{projection:t})},e.prototype.startRecording=function(t){if(t=t||1/0,1>t)throw p.makeError("Baobab.Cursor.startRecording: invalid max records.",{value:t});return this.state.recording=!0,this.archive?this:(this._lazyBind(),this.archive=new p.Archive(t),this)},e.prototype.stopRecording=function(){return this.state.recording=!1,this},e.prototype.undo=function(){var t=arguments.length<=0||void 0===arguments[0]?1:arguments[0];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}(h["default"]);r["default"]=d,"function"==typeof Symbol&&"undefined"!=typeof Symbol.iterator&&(d.prototype[Symbol.iterator]=function(){var t=this._get().data;if(!c["default"].array(t))throw Error("baobab.Cursor.@@iterate: cannot iterate a non-list type.");var e=0,r=this,n=t.length;return{next:function(){return n>e?{value:r.select(e++)}:{done:!0}}}}),s("set"),s("unset"),s("apply",c["default"]["function"]),s("push"),s("concat",c["default"].array),s("unshift"),s("splice",c["default"].splicer),s("merge",c["default"].object),s("deepMerge",c["default"].object),e.exports=r["default"]},{"./helpers":4,"./monkey":5,"./type":6,emmett:1}],4:[function(t,e,r){(function(e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){var r=void 0,n=void 0;for(r=0,n=t.length;n>r;r++)if(e(t[r]))return r;return-1}function a(t){var e=new Array(t.length),r=void 0,n=void 0;for(r=0,n=t.length;n>r;r++)e[r]=t[r];return e}function s(t){return a(t)}function u(t,e){return function(){t.apply(null,arguments),e.apply(null,arguments)}}function h(t){var e=t.source,r="";return t.global&&(r+="g"),t.multiline&&(r+="m"),t.ignoreCase&&(r+="i"),t.sticky&&(r+="y"),t.unicode&&(r+="u"),new RegExp(e,r)}function l(t,r){if(!r||"object"!=typeof r||r instanceof Error||r instanceof _.MonkeyDefinition||"ArrayBuffer"in e&&r instanceof ArrayBuffer)return r;if(P["default"].array(r)){if(t){var n=[],i=void 0,o=void 0;for(i=0,o=r.length;o>i;i++)n.push(l(!0,r[i]));return n}return a(r)}if(r instanceof Date)return new Date(r.getTime());if(r instanceof RegExp)return h(r);if(P["default"].object(r)){var s={},u=void 0;for(u in r)P["default"].lazyGetter(r,u)?Object.defineProperty(s,u,{get:Object.getOwnPropertyDescriptor(r,u).get,enumerable:!0,configurable:!0}):r.hasOwnProperty(u)&&(s[u]=t?l(!0,r[u]):r[u]);return s}return r}function f(t){return t||0===t||""===t?t:[]}function c(t,e){var r=!0,n=void 0;if(!t)return!1;for(n in e)if(P["default"].object(e[n]))r=r&&c(t[n],e[n]);else if(P["default"].array(e[n]))r=r&&!!~e[n].indexOf(t[n]);else if(t[n]!==e[n])return!1;return r}function p(t,e){if(!("object"!=typeof e||null===e||e instanceof _.Monkey)&&(Object.freeze(e),t))if(Array.isArray(e)){var r=void 0,n=void 0;for(r=0,n=e.length;n>r;r++)p(!0,e[r])}else{var i=void 0,o=void 0;for(o in e)P["default"].lazyGetter(e,o)||(i=e[o],i&&e.hasOwnProperty(o)&&"object"==typeof i&&!Object.isFrozen(i)&&p(!0,i))}}function d(t,e){if(!e)return B;var r=[],n=!0,i=t,a=void 0,s=void 0,u=void 0;for(s=0,u=e.length;u>s;s++){if(!i)return{data:void 0,solvedPath:e,exists:!1};if("function"==typeof e[s]){if(!P["default"].array(i))return B;if(a=o(i,e[s]),!~a)return B;r.push(a),i=i[a]}else if("object"==typeof e[s]){if(!P["default"].array(i))return B;if(a=o(i,function(t){return c(t,e[s])}),!~a)return B;r.push(a),i=i[a]}else r.push(e[s]),n="object"==typeof i&&e[s]in i,i=i[e[s]]}return{data:i,solvedPath:r,exists:n}}function y(t,e){var r=new Error(t);for(var n in e)r[n]=e[n];return r}function v(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];var i=r[0],o=void 0,a=void 0,s=void 0,u=void 0;for(a=1,s=r.length;s>a;a++){o=r[a];for(u in o)!t||!P["default"].object(o[u])||o[u]instanceof _.Monkey?i[u]=o[u]:i[u]=v(!0,i[u]||{},o[u])}return i}function g(t,e){for(var r=[],n=0,i=e.length;i>n;n++){var o=e[n];"."===o?n||(r=t.slice(0)):".."===o?r=(n?r:t).slice(0,-1):r.push(o)}return r}function m(t,e){var r=void 0,n=void 0,i=void 0,o=void 0,a=void 0,s=void 0,u=void 0,h=void 0,l=void 0;for(r=0,o=t.length;o>r;r++){if(u=t[r],!u.length)return!0;for(n=0,a=e.length;a>n;n++){if(h=e[n],!h||!h.length)return!0;for(i=0,s=h.length;s>i&&(l=h[i],l==u[i]);i++)if(i+1===s||i+1===u.length)return!0}}return!1}function b(t,e,r){for(var n=arguments.length,i=Array(n>3?n-3:0),o=3;n>o;o++)i[o-3]=arguments[o];return t.slice(0,e).concat(i).concat(t.slice(e+Math.max(0,r)))}r.__esModule=!0,r.arrayFrom=s,r.before=u,r.coercePath=f,r.getIn=d,r.makeError=y,r.solveRelativePath=g,r.solveUpdate=m,r.splice=b;var _=t("./monkey"),w=t("./type"),P=n(w),k=Function.prototype,j=function(){function t(e){i(this,t),this.size=e,this.records=[]}return t.prototype.get=function(){return this.records},t.prototype.add=function(t){return this.records.unshift(t),this.records.length>this.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}();r.Archive=j;var M=l.bind(null,!1),O=l.bind(null,!0);r.shallowClone=M,r.deepClone=O;var E="function"==typeof Object.freeze,x=E?p.bind(null,!1):k,C=E?p.bind(null,!0):k;r.freeze=x,r.deepFreeze=C;var B={data:void 0,solvedPath:null,exists:!1},D=v.bind(null,!1),z=v.bind(null,!0);r.shallowMerge=D,r.deepMerge=z;var A=function(){var t=0;return function(){return t++}}();r.uniqid=A}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./monkey":5,"./type":6}],5:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.__esModule=!0;var o=t("./type"),a=n(o),s=t("./update"),u=n(s),h=t("./helpers"),l=function c(t){var e=this;i(this,c);var r=a["default"].monkeyDefinition(t);if(!r)throw h.makeError("Baobab.monkey: invalid definition.",{definition:t});this.type=r,"object"===this.type?(this.getter=t.get,this.projection=t.cursors||{},this.paths=Object.keys(this.projection).map(function(t){return e.projection[t]})):(this.getter=t[t.length-1],this.projection=t.slice(0,-1),this.paths=this.projection),this.hasDynamicPaths=this.paths.some(a["default"].dynamicPath)};r.MonkeyDefinition=l;var f=function(){function t(e,r,n){var o=this;i(this,t),this.tree=e,this.path=r,this.definition=n,this.isRecursive=!1;var a=n.projection,s=h.solveRelativePath.bind(null,r.slice(0,-1));"object"===n.type?(this.projection=Object.keys(a).reduce(function(t,e){return t[e]=s(a[e]),t},{}),this.depPaths=Object.keys(this.projection).map(function(t){return o.projection[t]})):(this.projection=a.map(s),this.depPaths=this.projection),this.state={killed:!1},this.listener=function(t){var e=t.data.path;if(!o.state.killed){var r=h.solveUpdate([e],o.relatedPaths());r&&o.update()}},this.tree.on("write",this.listener),this.update()}return t.prototype.checkRecursivity=function(){var t=this;return this.isRecursive=this.depPaths.some(function(e){return!!a["default"].monkeyPath(t.tree._monkeys,e)}),this.isRecursive&&(this.tree.off("write",this.listener),this.tree.on("write",this.listener)),this},t.prototype.relatedPaths=function(){var t=this,e=void 0;return e=this.definition.hasDynamicPaths?this.depPaths.map(function(e){return h.getIn(t.tree._data,e).solvedPath}):this.depPaths,this.isRecursive?e.reduce(function(e,r){var n=a["default"].monkeyPath(t.tree._monkeys,r);if(!n)return e.concat([r]);var i=h.getIn(t.tree._monkeys,n).data;return e.concat(i.relatedPaths())},[]):e},t.prototype.update=function(){var t=this.tree.project(this.projection),e=function(t,e,r){var n=null,i=!1;return function(){return i||(n=e.getter.apply(t,"object"===e.type?[r]:r),t.options.immutable&&h.deepFreeze(n),i=!0),n}}(this.tree,this.definition,t);if(e.isLazyGetter=!0,this.tree.options.lazyMonkeys)this.tree._data=u["default"](this.tree._data,this.path,{type:"monkey",value:e},this.tree.options).data;else{var r=u["default"](this.tree._data,this.path,{type:"set",value:e()},this.tree.options);"data"in r&&(this.tree._data=r.data)}return this},t.prototype.release=function(){this.tree.off("write",this.listener),this.state.killed=!0,delete this.projection,delete this.depPaths,delete this.tree},t}();r.Monkey=f},{"./helpers":4,"./type":6,"./update":7}],6:[function(t,e,r){"use strict";function n(t,e){return e.some(function(e){return o[e](t)})}r.__esModule=!0;var i=t("./monkey"),o={};o.array=function(t){return Array.isArray(t)},o.object=function(t){return t&&"object"==typeof t&&!Array.isArray(t)&&!(t instanceof Date)&&!(t instanceof RegExp)&&!("function"==typeof Map&&t instanceof Map)&&!("function"==typeof Set&&t instanceof Set)},o.string=function(t){return"string"==typeof t},o.number=function(t){return"number"==typeof t},o["function"]=function(t){return"function"==typeof t},o.primitive=function(t){return t!==Object(t)},o.splicer=function(t){return!o.array(t)||t.length<2?!1:n(t[0],["number","function","object"])&&o.number(t[1])};var a=["string","number","function","object"];o.path=function(t){return t||0===t||""===t?[].concat(t).every(function(t){return n(t,a)}):!1},o.dynamicPath=function(t){return t.some(function(t){return o["function"](t)||o.object(t)})},o.monkeyPath=function(t,e){var r=[],n=t,o=void 0,a=void 0;for(o=0,a=e.length;a>o;o++){if(r.push(e[o]),"object"!=typeof n)return null;if(n=n[e[o]],n instanceof i.Monkey)return r}return null},o.lazyGetter=function(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return r&&r.get&&r.get.isLazyGetter===!0},o.monkeyDefinition=function(t){return o.object(t)?o["function"](t.get)&&(!t.cursors||o.object(t.cursors)&&Object.keys(t.cursors).every(function(e){return o.path(t.cursors[e])}))?"object":null:o.array(t)&&o["function"](t[t.length-1])&&t.slice(0,-1).every(function(t){return o.path(t)})?"array":null},o.watcherMapping=function(t){return o.object(t)&&Object.keys(t).every(function(e){return o.path(t[e])})};var s=["set","apply","push","unshift","concat","deepMerge","merge","splice","unset"];o.operationType=function(t){return"string"==typeof t&&!!~s.indexOf(t)},r["default"]=o,e.exports=r["default"]},{"./monkey":5}],7:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e,r){return u.makeError('Baobab.update: cannot apply the "'+t+'" on '+("a non "+e+" (path: /"+r.join("/")+")."),{path:r})}function o(t,e,r){var n=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],o=r.type,a=r.value,h={root:t},l=["root"].concat(e),f=[],c=h,p=void 0,d=void 0,y=void 0;for(p=0,d=l.length;d>p;p++){if(y=l[p],p>0&&f.push(y),p===d-1){if("set"===o){if(n.pure&&c[y]===a)return{node:c[y]};s["default"].lazyGetter(c,y)?Object.defineProperty(c,y,{value:a,enumerable:!0,configurable:!0}):n.persistent?c[y]=u.shallowClone(a):c[y]=a}else if("monkey"===o)Object.defineProperty(c,y,{get:a,enumerable:!0,configurable:!0});else if("apply"===o){var v=a(c[y]);if(n.pure&&c[y]===v)return{node:c[y]};s["default"].lazyGetter(c,y)?Object.defineProperty(c,y,{value:v,enumerable:!0,configurable:!0}):n.persistent?c[y]=u.shallowClone(v):c[y]=v}else if("push"===o){if(!s["default"].array(c[y]))throw i("push","array",f);n.persistent?c[y]=c[y].concat([a]):c[y].push(a)}else if("unshift"===o){if(!s["default"].array(c[y]))throw i("unshift","array",f);n.persistent?c[y]=[a].concat(c[y]):c[y].unshift(a)}else if("concat"===o){if(!s["default"].array(c[y]))throw i("concat","array",f);n.persistent?c[y]=c[y].concat(a):c[y].push.apply(c[y],a)}else if("splice"===o){if(!s["default"].array(c[y]))throw i("splice","array",f);n.persistent?c[y]=u.splice.apply(null,[c[y]].concat(a)):c[y].splice.apply(c[y],a)}else if("unset"===o)s["default"].object(c)?delete c[y]:s["default"].array(c)&&c.splice(y,1);else if("merge"===o){if(!s["default"].object(c[y]))throw i("merge","object",f);n.persistent?c[y]=u.shallowMerge({},c[y],a):c[y]=u.shallowMerge(c[y],a)}else if("deepMerge"===o){if(!s["default"].object(c[y]))throw i("deepMerge","object",f);n.persistent?c[y]=u.deepMerge({},c[y],a):c[y]=u.deepMerge(c[y],a)}n.immutable&&u.deepFreeze(c);break}s["default"].primitive(c[y])?c[y]={}:n.persistent&&(c[y]=u.shallowClone(c[y])),n.immutable&&d>0&&u.freeze(c),c=c[y]}return s["default"].lazyGetter(c,y)?{data:h.root}:{data:h.root,node:c[y]}}r.__esModule=!0,r["default"]=o;var a=t("./type"),s=n(a),u=t("./helpers");e.exports=r["default"]},{"./helpers":4,"./type":6}],8:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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)}r.__esModule=!0;var a=t("emmett"),s=n(a),u=t("./cursor"),h=n(u),l=t("./type"),f=n(l),c=t("./helpers"),p=function(t){function e(r,n){var o=this;i(this,e),t.call(this),this.tree=r,this.mapping=null,this.state={killed:!1},this.refresh(n),this.handler=function(t){if(!o.state.killed){var e=o.getWatchedPaths();return c.solveUpdate(t.data.paths,e)?o.emit("update"):void 0}},this.tree.on("update",this.handler)}return o(e,t),e.prototype.getWatchedPaths=function(){var t=this,e=Object.keys(this.mapping).map(function(e){var r=t.mapping[e];return r instanceof h["default"]?r.solvedPath:t.mapping[e]});return e.reduce(function(e,r){if(f["default"].dynamicPath(r)&&(r=c.getIn(t.tree._data,r).solvedPath),!r)return e;var n=f["default"].monkeyPath(t.tree._monkeys,r);return n?e.concat(c.getIn(t.tree._monkeys,n).data.relatedPaths()):e.concat([r])},[])},e.prototype.getCursors=function(){var t=this,e={};return Object.keys(this.mapping).forEach(function(r){var n=t.mapping[r];n instanceof h["default"]?e[r]=n:e[r]=t.tree.select(n)}),e},e.prototype.refresh=function(t){if(!f["default"].watcherMapping(t))throw c.makeError("Baobab.watch: invalid mapping.",{mapping:t});this.mapping=t;var e={};for(var r in t)e[r]=t[r]instanceof h["default"]?t[r].path:t[r];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()}, +/* baobab.js - Version: 2.2.0 - Author: Yomguithereal (Guillaume Plique) */ +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Baobab=t()}}(function(){var t;return function e(t,r,n){function i(a,s){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var h=new Error("Cannot find module '"+a+"'");throw h.code="MODULE_NOT_FOUND",h}var l=r[a]={exports:{}};t[a][0].call(l.exports,function(e){var r=t[a][1][e];return i(r?r:e)},l,l.exports,e,t,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;ao;o++)e.call(r||null,n[o],t[n[o]])}function a(t,e){t=t||[];var r,n,i=[];for(n=0,r=t.length;r>n;n++)t[n].fn!==e&&i.push(t[n]);return i}var s={once:"boolean",scope:"object"},u=0,h=function(){this._enabled=!0,this.unbindAll()};h.prototype.unbindAll=function(){return this._handlers={},this._handlersAll=[],this._handlersComplex=[],this},h.prototype.on=function(t,e,r){var n,a,h,l,f,c,p;if(i(t))return o(t,function(t,r){this.on(t,r,e)},this),this;for("function"==typeof t&&(r=e,e=t,t=null),f=[].concat(t),n=0,a=f.length;a>n;n++){if(l=f[n],p={order:u++,fn:e},"string"==typeof l||"symbol"==typeof l)this._handlers[l]||(this._handlers[l]=[]),c=this._handlers[l],p.type=l;else if(l instanceof RegExp)c=this._handlersComplex,p.pattern=l;else{if(null!==l)throw Error("Emitter.on: invalid event.");c=this._handlersAll}for(h in r||{})s[h]&&(p[h]=r[h]);c.push(p)}return this},h.prototype.once=function(){var t=Array.prototype.slice.call(arguments),r=t.length-1;return i(t[r])&&t.length>1?t[r]=e(t[r],{once:!0}):t.push({once:!0}),this.on.apply(this,t)},h.prototype.off=function(t,e){var r,n,s,u;if(1===arguments.length&&"function"==typeof t){e=arguments[0];for(s in this._handlers)this._handlers[s]=a(this._handlers[s],e),0===this._handlers[s].length&&delete this._handlers[s];this._handlersAll=a(this._handlersAll,e),this._handlersComplex=a(this._handlersComplex,e)}else if(1!==arguments.length||"string"!=typeof t&&"symbol"!=typeof t)if(2===arguments.length){var h=[].concat(t);for(r=0,n=h.length;n>r;r++)u=h[r],this._handlers[u]=a(this._handlers[u],e),0===(this._handlers[u]||[]).length&&delete this._handlers[u]}else i(t)&&o(t,this.off,this);else delete this._handlers[t];return this},h.prototype.listeners=function(t){var e,r,n,i=this._handlersAll||[],o=!1;if(!t)throw Error("Emitter.listeners: no event provided.");for(i=i.concat(this._handlers[t]||[]),r=0,n=this._handlersComplex.length;n>r;r++)e=this._handlersComplex[r],~t.search(e.pattern)&&(o=!0,i.push(e));return this._handlersAll.length||o?i.sort(function(t,e){return t.order-e.order}):i.slice(0)},h.prototype.emit=function(t,e){if(!this._enabled)return this;if(i(t))return o(t,this.emit,this),this;var r,n,a,s,u,h,l,f,c=[].concat(t),p=[];for(u=0,l=c.length;l>u;u++){for(a=this.listeners(c[u]),h=0,f=a.length;f>h;h++)s=a[h],r={type:c[u],target:this},arguments.length>1&&(r.data=e),s.fn.call("scope"in s?s.scope:this,r),s.once&&p.push(s);for(h=p.length-1;h>=0;h--)n=p[h].type?this._handlers[p[h].type]:p[h].pattern?this._handlersComplex:this._handlersAll,n.splice(n.indexOf(p[h]),1)}return this},h.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},h.prototype.disable=function(){return this._enabled=!1,this},h.prototype.enable=function(){return this._enabled=!0,this},h.version="3.1.1","undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=h),n.Emitter=h):"function"==typeof t&&t.amd?t("emmett",[],function(){return h}):this.Emitter=h}).call(this)},{}],2:[function(t,e,r){"use strict";function n(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e["default"]=t,e}function i(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(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 s(t){return"λ"+t.map(function(t){return g["default"]["function"](t)||g["default"].object(t)?"#"+B()+"#":t}).join("λ")}r.__esModule=!0;var u=Object.assign||function(t){for(var e=1;e1&&(t=P(arguments)),!g["default"].path(t))throw O("Baobab.select: invalid path.",{path:t});t=[].concat(t);var e=s(t),r=this._cursors[e];return r||(r=new c["default"](this,t,e),this._cursors[e]=r),this.emit("select",{path:t,cursor:r}),r},e.prototype.update=function(t,e){var r=this;if(t=k(t),!g["default"].operationType(e.type))throw O('Baobab.update: unknown operation type "'+e.type+'".',{operation:e});var n=M(this._data,t),i=n.solvedPath,o=n.exists;if(!i)throw O("Baobab.update: could not solve the given path.",{path:i});var a=g["default"].monkeyPath(this._monkeys,i);if(a&&i.length>a.length)throw O("Baobab.update: attempting to update a read-only path.",{path:i});if("unset"!==e.type||o){var h=e;if(/merge/.test(e.type)){var l=M(this._monkeys,i).data;g["default"].object(l)&&(h=x(h),/deep/.test(h.type)?h.value=E({},l,h.value):h.value=C({},l,h.value))}this._transaction.length||(this._previousData=this._data);var f=b["default"](this._data,i,h,this.options),c=f.data,p=f.node;if(!("data"in f))return p;var d=i.concat("push"===e.type?p.length-1:[]),y=s(d);return this._data=c,this._affectedPathsIndex[y]=!0,this._transaction.push(u({},e,{path:d})),this._refreshMonkeys(p,i,e.type),this.emit("write",{path:d}),this.options.autoCommit?this.options.asynchronous?(this._future||(this._future=setTimeout(function(){return r.commit()},0)),p):(this.commit(),p):p}},e.prototype.commit=function(){this._future&&(this._future=clearTimeout(this._future));var t=Object.keys(this._affectedPathsIndex).map(function(t){return"λ"!==t?t.split("λ").slice(1):[]}),e=this.validate(t);if(e)return this;var r=this._transaction,n=this._previousData;return this._affectedPathsIndex={},this._transaction=[],this._previousData=this._data,this.emit("update",{paths:t,currentData:this._data,transaction:r,previousData:n}),this},e.prototype.watch=function(t){return new y["default"](this,t)},e.prototype.release=function(){var t=void 0;this.emit("release"),delete this.root,delete this._data,delete this._previousData,delete this._transaction,delete this._affectedPathsIndex,delete this._monkeys;for(t in 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}(l["default"]);r["default"]=z,z.monkey=function(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];if(!e.length)throw new Error("Baobab.monkey: missing definition.");return 1===e.length?new p.MonkeyDefinition(e[0]):new p.MonkeyDefinition(e)},z.dynamicNode=z.monkey,z.Cursor=c["default"],z.MonkeyDefinition=p.MonkeyDefinition,z.Monkey=p.Monkey,z.type=g["default"],z.helpers=w,Object.defineProperty(z,"version",{value:"2.2.0"}),r["default"]=z,e.exports=r["default"]},{"./cursor":3,"./helpers":4,"./monkey":5,"./type":6,"./update":7,"./watcher":8,emmett:1}],3:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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 a(t,e){if(!e)throw p.makeError("Baobab.Cursor."+t+": "+("cannot use "+t+" on an unresolved dynamic path."),{path:e})}function s(t,e){d.prototype[t]=function(r,n){if(arguments.length>2)throw p.makeError("Baobab.Cursor."+t+": too many arguments.");if(1===arguments.length&&"unset"!==t&&(n=r,r=[]),r=p.coercePath(r),!c["default"].path(r))throw p.makeError("Baobab.Cursor."+t+": invalid path.",{path:r});if(e&&!e(n))throw p.makeError("Baobab.Cursor."+t+": invalid value.",{path:r,value:n});var i=this.solvedPath.concat(r);return this.tree.update(i,{type:t,value:n})}}r.__esModule=!0;var u=t("emmett"),h=n(u),l=t("./monkey"),f=t("./type"),c=n(f),p=t("./helpers"),d=function(t){function e(r,n,o){var a=this;i(this,e),t.call(this),n=n||[],this._identity="[object Cursor]",this._archive=null,this.tree=r,this.path=n,this.hash=o,this.state={killed:!1,recording:!1,undoing:!1},this._dynamicPath=c["default"].dynamicPath(this.path),this._monkeyPath=c["default"].monkeyPath(this.tree._monkeys,this.path),this._dynamicPath?this.solvedPath=p.getIn(this.tree._data,this.path).solvedPath:this.solvedPath=this.path,this._writeHandler=function(t){var e=t.data;!a.state.killed&&p.solveUpdate([e.path],a._getComparedPaths())&&(a.solvedPath=p.getIn(a.tree._data,a.path).solvedPath)};var s=function(t){var e=a,r=Object.defineProperties({},{previousData:{get:function(){return p.getIn(t,e.solvedPath).data},configurable:!0,enumerable:!0},currentData:{get:function(){return e.get()},configurable:!0,enumerable:!0}});return a.state.recording&&!a.state.undoing&&a.archive.add(r.previousData),a.state.undoing=!1,a.emit("update",r)};this._updateHandler=function(t){if(!a.state.killed){var e=t.data,r=e.paths,n=e.previousData,i=s.bind(a,n),o=a._getComparedPaths();return p.solveUpdate(r,o)?i():void 0}};var u=!1;this._lazyBind=function(){return u?void 0:(u=!0,a._dynamicPath&&a.tree.on("write",a._writeHandler),a.tree.on("update",a._updateHandler))},this._dynamicPath?this._lazyBind():(this.on=p.before(this._lazyBind,this.on.bind(this)),this.once=p.before(this._lazyBind,this.once.bind(this)))}return o(e,t),e.prototype._getComparedPaths=function(){var t=this._monkeyPath?p.getIn(this.tree._monkeys,this._monkeyPath).data.relatedPaths():[];return[this.solvedPath].concat(t)},e.prototype.isRoot=function(){return!this.path.length},e.prototype.isLeaf=function(){return c["default"].primitive(this._get().data)},e.prototype.isBranch=function(){return!this.isRoot()&&!this.isLeaf()},e.prototype.root=function(){return this.tree.select()},e.prototype.select=function(t){return arguments.length>1&&(t=p.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(a("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(){a("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(){a("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(){a("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(){a("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){a("map",this.solvedPath);var r=this._get().data,n=arguments.length;if(!c["default"].array(r))throw Error("baobab.Cursor.map: cannot map a non-list type.");return r.map(function(i,o){return t.call(n>1?e:this,this.select(o),o,r)},this)},e.prototype._get=function(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];if(!c["default"].path(t))throw p.makeError("Baobab.Cursor.getters: invalid path.",{path:t});return this.solvedPath?p.getIn(this.tree._data,this.solvedPath.concat(t)):{data:void 0,solvedPath:null,exists:!1}},e.prototype.exists=function(t){return t=p.coercePath(t),arguments.length>1&&(t=p.arrayFrom(arguments)),this._get(t).exists},e.prototype.get=function(t){t=p.coercePath(t),arguments.length>1&&(t=p.arrayFrom(arguments));var e=this._get(t),r=e.data,n=e.solvedPath;return this.tree.emit("get",{data:r,solvedPath:n,path:this.path.concat(t)}),r},e.prototype.serialize=function(t){if(t=p.coercePath(t),arguments.length>1&&(t=p.arrayFrom(arguments)),!c["default"].path(t))throw p.makeError("Baobab.Cursor.getters: invalid path.",{path:t});if(this.solvedPath){var e=this.solvedPath.concat(t),r=p.deepClone(p.getIn(this.tree._data,e).data),n=p.getIn(this.tree._monkeys,e).data,i=function o(t,e){if(c["default"].object(e)&&c["default"].object(t))for(var r in e)e[r]instanceof l.Monkey?delete t[r]:o(t[r],e[r])};return i(r,n),r}},e.prototype.project=function(t){if(c["default"].object(t)){var e={};for(var r in t)e[r]=this.get(t[r]);return e}if(c["default"].array(t)){for(var e=[],n=0,i=t.length;i>n;n++)e.push(this.get(t[n]));return e}throw p.makeError("Baobab.Cursor.project: wrong projection.",{projection:t})},e.prototype.startRecording=function(t){if(t=t||1/0,1>t)throw p.makeError("Baobab.Cursor.startRecording: invalid max records.",{value:t});return this.state.recording=!0,this.archive?this:(this._lazyBind(),this.archive=new p.Archive(t),this)},e.prototype.stopRecording=function(){return this.state.recording=!1,this},e.prototype.undo=function(){var t=arguments.length<=0||void 0===arguments[0]?1:arguments[0];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}(h["default"]);r["default"]=d,"function"==typeof Symbol&&"undefined"!=typeof Symbol.iterator&&(d.prototype[Symbol.iterator]=function(){var t=this._get().data;if(!c["default"].array(t))throw Error("baobab.Cursor.@@iterate: cannot iterate a non-list type.");var e=0,r=this,n=t.length;return{next:function(){return n>e?{value:r.select(e++)}:{done:!0}}}}),s("set"),s("unset"),s("apply",c["default"]["function"]),s("push"),s("concat",c["default"].array),s("unshift"),s("splice",c["default"].splicer),s("merge",c["default"].object),s("deepMerge",c["default"].object),e.exports=r["default"]},{"./helpers":4,"./monkey":5,"./type":6,emmett:1}],4:[function(t,e,r){(function(e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){var r=void 0,n=void 0;for(r=0,n=t.length;n>r;r++)if(e(t[r]))return r;return-1}function a(t){var e=new Array(t.length),r=void 0,n=void 0;for(r=0,n=t.length;n>r;r++)e[r]=t[r];return e}function s(t){return a(t)}function u(t,e){return function(){t.apply(null,arguments),e.apply(null,arguments)}}function h(t){var e=t.source,r="";return t.global&&(r+="g"),t.multiline&&(r+="m"),t.ignoreCase&&(r+="i"),t.sticky&&(r+="y"),t.unicode&&(r+="u"),new RegExp(e,r)}function l(t,r){if(!r||"object"!=typeof r||r instanceof Error||r instanceof _.MonkeyDefinition||"ArrayBuffer"in e&&r instanceof ArrayBuffer)return r;if(P["default"].array(r)){if(t){var n=[],i=void 0,o=void 0;for(i=0,o=r.length;o>i;i++)n.push(l(!0,r[i]));return n}return a(r)}if(r instanceof Date)return new Date(r.getTime());if(r instanceof RegExp)return h(r);if(P["default"].object(r)){var s={},u=void 0;for(u in r)P["default"].lazyGetter(r,u)?Object.defineProperty(s,u,{get:Object.getOwnPropertyDescriptor(r,u).get,enumerable:!0,configurable:!0}):r.hasOwnProperty(u)&&(s[u]=t?l(!0,r[u]):r[u]);return s}return r}function f(t){return t||0===t||""===t?t:[]}function c(t,e){var r=!0,n=void 0;if(!t)return!1;for(n in e)if(P["default"].object(e[n]))r=r&&c(t[n],e[n]);else if(P["default"].array(e[n]))r=r&&!!~e[n].indexOf(t[n]);else if(t[n]!==e[n])return!1;return r}function p(t,e){if(!("object"!=typeof e||null===e||e instanceof _.Monkey)&&(Object.freeze(e),t))if(Array.isArray(e)){var r=void 0,n=void 0;for(r=0,n=e.length;n>r;r++)p(!0,e[r])}else{var i=void 0,o=void 0;for(o in e)P["default"].lazyGetter(e,o)||(i=e[o],i&&e.hasOwnProperty(o)&&"object"==typeof i&&!Object.isFrozen(i)&&p(!0,i))}}function d(t,e){if(!e)return B;var r=[],n=!0,i=t,a=void 0,s=void 0,u=void 0;for(s=0,u=e.length;u>s;s++){if(!i)return{data:void 0,solvedPath:e,exists:!1};if("function"==typeof e[s]){if(!P["default"].array(i))return B;if(a=o(i,e[s]),!~a)return B;r.push(a),i=i[a]}else if("object"==typeof e[s]){if(!P["default"].array(i))return B;if(a=o(i,function(t){return c(t,e[s])}),!~a)return B;r.push(a),i=i[a]}else r.push(e[s]),n="object"==typeof i&&e[s]in i,i=i[e[s]]}return{data:i,solvedPath:r,exists:n}}function y(t,e){var r=new Error(t);for(var n in e)r[n]=e[n];return r}function v(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];var i=r[0],o=void 0,a=void 0,s=void 0,u=void 0;for(a=1,s=r.length;s>a;a++){o=r[a];for(u in o)!t||!P["default"].object(o[u])||o[u]instanceof _.Monkey?i[u]=o[u]:i[u]=v(!0,i[u]||{},o[u])}return i}function g(t,e){for(var r=[],n=0,i=e.length;i>n;n++){var o=e[n];"."===o?n||(r=t.slice(0)):".."===o?r=(n?r:t).slice(0,-1):r.push(o)}return r}function m(t,e){var r=void 0,n=void 0,i=void 0,o=void 0,a=void 0,s=void 0,u=void 0,h=void 0,l=void 0;for(r=0,o=t.length;o>r;r++){if(u=t[r],!u.length)return!0;for(n=0,a=e.length;a>n;n++){if(h=e[n],!h||!h.length)return!0;for(i=0,s=h.length;s>i&&(l=h[i],l==u[i]);i++)if(i+1===s||i+1===u.length)return!0}}return!1}function b(t,e,r){for(var n=arguments.length,i=Array(n>3?n-3:0),o=3;n>o;o++)i[o-3]=arguments[o];return t.slice(0,e).concat(i).concat(t.slice(e+Math.max(0,r)))}r.__esModule=!0,r.arrayFrom=s,r.before=u,r.coercePath=f,r.getIn=d,r.makeError=y,r.solveRelativePath=g,r.solveUpdate=m,r.splice=b;var _=t("./monkey"),w=t("./type"),P=n(w),k=Function.prototype,j=function(){function t(e){i(this,t),this.size=e,this.records=[]}return t.prototype.get=function(){return this.records},t.prototype.add=function(t){return this.records.unshift(t),this.records.length>this.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}();r.Archive=j;var M=l.bind(null,!1),O=l.bind(null,!0);r.shallowClone=M,r.deepClone=O;var E="function"==typeof Object.freeze,x=E?p.bind(null,!1):k,C=E?p.bind(null,!0):k;r.freeze=x,r.deepFreeze=C;var B={data:void 0,solvedPath:null,exists:!1},D=v.bind(null,!1),z=v.bind(null,!0);r.shallowMerge=D,r.deepMerge=z;var A=function(){var t=0;return function(){return t++}}();r.uniqid=A}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./monkey":5,"./type":6}],5:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}r.__esModule=!0;var o=t("./type"),a=n(o),s=t("./update"),u=n(s),h=t("./helpers"),l=function c(t){var e=this;i(this,c);var r=a["default"].monkeyDefinition(t);if(!r)throw h.makeError("Baobab.monkey: invalid definition.",{definition:t});this.type=r,"object"===this.type?(this.getter=t.get,this.projection=t.cursors||{},this.paths=Object.keys(this.projection).map(function(t){return e.projection[t]})):(this.getter=t[t.length-1],this.projection=t.slice(0,-1),this.paths=this.projection),this.hasDynamicPaths=this.paths.some(a["default"].dynamicPath)};r.MonkeyDefinition=l;var f=function(){function t(e,r,n){var o=this;i(this,t),this.tree=e,this.path=r,this.definition=n,this.isRecursive=!1;var a=n.projection,s=h.solveRelativePath.bind(null,r.slice(0,-1));"object"===n.type?(this.projection=Object.keys(a).reduce(function(t,e){return t[e]=s(a[e]),t},{}),this.depPaths=Object.keys(this.projection).map(function(t){return o.projection[t]})):(this.projection=a.map(s),this.depPaths=this.projection),this.state={killed:!1},this.listener=function(t){var e=t.data.path;if(!o.state.killed){var r=h.solveUpdate([e],o.relatedPaths());r&&o.update()}},this.tree.on("write",this.listener),this.update()}return t.prototype.checkRecursivity=function(){var t=this;return this.isRecursive=this.depPaths.some(function(e){return!!a["default"].monkeyPath(t.tree._monkeys,e)}),this.isRecursive&&(this.tree.off("write",this.listener),this.tree.on("write",this.listener)),this},t.prototype.relatedPaths=function(){var t=this,e=void 0;return e=this.definition.hasDynamicPaths?this.depPaths.map(function(e){return h.getIn(t.tree._data,e).solvedPath}):this.depPaths,this.isRecursive?e.reduce(function(e,r){var n=a["default"].monkeyPath(t.tree._monkeys,r);if(!n)return e.concat([r]);var i=h.getIn(t.tree._monkeys,n).data;return e.concat(i.relatedPaths())},[]):e},t.prototype.update=function(){var t=this.tree.project(this.projection),e=function(t,e,r){var n=null,i=!1;return function(){return i||(n=e.getter.apply(t,"object"===e.type?[r]:r),t.options.immutable&&h.deepFreeze(n),i=!0),n}}(this.tree,this.definition,t);if(e.isLazyGetter=!0,this.tree.options.lazyMonkeys)this.tree._data=u["default"](this.tree._data,this.path,{type:"monkey",value:e},this.tree.options).data;else{var r=u["default"](this.tree._data,this.path,{type:"set",value:e()},this.tree.options);"data"in r&&(this.tree._data=r.data)}return this},t.prototype.release=function(){this.tree.off("write",this.listener),this.state.killed=!0,delete this.projection,delete this.depPaths,delete this.tree},t}();r.Monkey=f},{"./helpers":4,"./type":6,"./update":7}],6:[function(t,e,r){"use strict";function n(t,e){return e.some(function(e){return o[e](t)})}r.__esModule=!0;var i=t("./monkey"),o={};o.array=function(t){return Array.isArray(t)},o.object=function(t){return t&&"object"==typeof t&&!Array.isArray(t)&&!(t instanceof Date)&&!(t instanceof RegExp)&&!("function"==typeof Map&&t instanceof Map)&&!("function"==typeof Set&&t instanceof Set)},o.string=function(t){return"string"==typeof t},o.number=function(t){return"number"==typeof t},o["function"]=function(t){return"function"==typeof t},o.primitive=function(t){return t!==Object(t)},o.splicer=function(t){return!o.array(t)||t.length<2?!1:n(t[0],["number","function","object"])&&o.number(t[1])};var a=["string","number","function","object"];o.path=function(t){return t||0===t||""===t?[].concat(t).every(function(t){return n(t,a)}):!1},o.dynamicPath=function(t){return t.some(function(t){return o["function"](t)||o.object(t)})},o.monkeyPath=function(t,e){var r=[],n=t,o=void 0,a=void 0;for(o=0,a=e.length;a>o;o++){if(r.push(e[o]),"object"!=typeof n)return null;if(n=n[e[o]],n instanceof i.Monkey)return r}return null},o.lazyGetter=function(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return r&&r.get&&r.get.isLazyGetter===!0},o.monkeyDefinition=function(t){return o.object(t)?o["function"](t.get)&&(!t.cursors||o.object(t.cursors)&&Object.keys(t.cursors).every(function(e){return o.path(t.cursors[e])}))?"object":null:o.array(t)&&o["function"](t[t.length-1])&&t.slice(0,-1).every(function(t){return o.path(t)})?"array":null},o.watcherMapping=function(t){return o.object(t)&&Object.keys(t).every(function(e){return o.path(t[e])})};var s=["set","apply","push","unshift","concat","deepMerge","merge","splice","unset"];o.operationType=function(t){return"string"==typeof t&&!!~s.indexOf(t)},r["default"]=o,e.exports=r["default"]},{"./monkey":5}],7:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e,r){return u.makeError('Baobab.update: cannot apply the "'+t+'" on '+("a non "+e+" (path: /"+r.join("/")+")."),{path:r})}function o(t,e,r){var n=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],o=r.type,a=r.value,h={root:t},l=["root"].concat(e),f=[],c=h,p=void 0,d=void 0,y=void 0;for(p=0,d=l.length;d>p;p++){if(y=l[p],p>0&&f.push(y),p===d-1){if("set"===o){if(n.pure&&c[y]===a)return{node:c[y]};s["default"].lazyGetter(c,y)?Object.defineProperty(c,y,{value:a,enumerable:!0,configurable:!0}):n.persistent?c[y]=u.shallowClone(a):c[y]=a}else if("monkey"===o)Object.defineProperty(c,y,{get:a,enumerable:!0,configurable:!0});else if("apply"===o){var v=a(c[y]);if(n.pure&&c[y]===v)return{node:c[y]};s["default"].lazyGetter(c,y)?Object.defineProperty(c,y,{value:v,enumerable:!0,configurable:!0}):n.persistent?c[y]=u.shallowClone(v):c[y]=v}else if("push"===o){if(!s["default"].array(c[y]))throw i("push","array",f);n.persistent?c[y]=c[y].concat([a]):c[y].push(a)}else if("unshift"===o){if(!s["default"].array(c[y]))throw i("unshift","array",f);n.persistent?c[y]=[a].concat(c[y]):c[y].unshift(a)}else if("concat"===o){if(!s["default"].array(c[y]))throw i("concat","array",f);n.persistent?c[y]=c[y].concat(a):c[y].push.apply(c[y],a)}else if("splice"===o){if(!s["default"].array(c[y]))throw i("splice","array",f);n.persistent?c[y]=u.splice.apply(null,[c[y]].concat(a)):c[y].splice.apply(c[y],a)}else if("unset"===o)s["default"].object(c)?delete c[y]:s["default"].array(c)&&c.splice(y,1);else if("merge"===o){if(!s["default"].object(c[y]))throw i("merge","object",f);n.persistent?c[y]=u.shallowMerge({},c[y],a):c[y]=u.shallowMerge(c[y],a)}else if("deepMerge"===o){if(!s["default"].object(c[y]))throw i("deepMerge","object",f);n.persistent?c[y]=u.deepMerge({},c[y],a):c[y]=u.deepMerge(c[y],a)}n.immutable&&u.deepFreeze(c);break}s["default"].primitive(c[y])?c[y]={}:n.persistent&&(c[y]=u.shallowClone(c[y])),n.immutable&&d>0&&u.freeze(c),c=c[y]}return s["default"].lazyGetter(c,y)?{data:h.root}:{data:h.root,node:c[y]}}r.__esModule=!0,r["default"]=o;var a=t("./type"),s=n(a),u=t("./helpers");e.exports=r["default"]},{"./helpers":4,"./type":6}],8:[function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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)}r.__esModule=!0;var a=t("emmett"),s=n(a),u=t("./cursor"),h=n(u),l=t("./type"),f=n(l),c=t("./helpers"),p=function(t){function e(r,n){var o=this;i(this,e),t.call(this),this.tree=r,this.mapping=null,this.state={killed:!1},this.refresh(n),this.handler=function(t){if(!o.state.killed){var e=o.getWatchedPaths();return c.solveUpdate(t.data.paths,e)?o.emit("update"):void 0}},this.tree.on("update",this.handler)}return o(e,t),e.prototype.getWatchedPaths=function(){var t=this,e=Object.keys(this.mapping).map(function(e){var r=t.mapping[e];return r instanceof h["default"]?r.solvedPath:t.mapping[e]});return e.reduce(function(e,r){if(f["default"].dynamicPath(r)&&(r=c.getIn(t.tree._data,r).solvedPath),!r)return e;var n=f["default"].monkeyPath(t.tree._monkeys,r);return n?e.concat(c.getIn(t.tree._monkeys,n).data.relatedPaths()):e.concat([r])},[])},e.prototype.getCursors=function(){var t=this,e={};return Object.keys(this.mapping).forEach(function(r){var n=t.mapping[r];n instanceof h["default"]?e[r]=n:e[r]=t.tree.select(n)}),e},e.prototype.refresh=function(t){if(!f["default"].watcherMapping(t))throw c.makeError("Baobab.watch: invalid mapping.",{mapping:t});this.mapping=t;var e={};for(var r in t)e[r]=t[r]instanceof h["default"]?t[r].path:t[r];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}(s["default"]);r["default"]=p,e.exports=r["default"]},{"./cursor":3,"./helpers":4,"./type":6,emmett:1}]},{},[2])(2)}); \ No newline at end of file diff --git a/package.json b/package.json index 50b30c7..12c87c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "baobab", - "version": "2.1.2", + "version": "2.2.0", "description": "JavaScript persistent data tree with cursors.", "main": "./dist/baobab.js", "dependencies": { diff --git a/src/baobab.js b/src/baobab.js index 9e30875..bf16020 100644 --- a/src/baobab.js +++ b/src/baobab.js @@ -561,7 +561,7 @@ Baobab.helpers = helpers; * Version */ Object.defineProperty(Baobab, 'version', { - value: '2.1.2' + value: '2.2.0' });