From 2d7ea098947ded91988b4cbde0304be7df9d5109 Mon Sep 17 00:00:00 2001 From: Yomguithereal Date: Fri, 6 Feb 2015 10:33:50 +0100 Subject: [PATCH] Bump version --- bower.json | 2 +- build/baobab.min.js | 4 ++-- index.js | 2 +- package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 55fa4e9..2f6b978 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "baobab", "main": "build/baobab.min.js", - "version": "0.3.0", + "version": "0.3.1", "homepage": "https://github.com/Yomguithereal/baobab", "author": { "name": "Guillaume Plique", diff --git a/build/baobab.min.js b/build/baobab.min.js index d7bd338..843043e 100644 --- a/build/baobab.min.js +++ b/build/baobab.min.js @@ -1,2 +1,2 @@ -/* baobab.js - Version: 0.3.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;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Baobab=t()}}(function(){var t;return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var h="function"==typeof require&&require;if(!a&&h)return h(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){var r=t[s][1][e];return o(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s0)){var r=n.shift();r()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}):function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=r,n.addListener=r,n.once=r,n.off=r,n.removeListener=r,n.removeAllListeners=r,n.emit=r,n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(e,r,n){(function(){"use strict";var e={once:"boolean",scope:"object"},o=function(){this._enabled=!0,this._children=[],this._handlers={},this._handlersAll=[]};o.prototype.on=function(t,r,n){var i,s,a,h,u,c;if("function"==typeof r){for(u="string"==typeof t?[t]:t,i=0,s=u.length;i!==s;i+=1)if(h=u[i]){this._handlers[h]||(this._handlers[h]=[]),c={handler:r};for(a in n||{}){if(!e[a])throw new Error('The option "'+a+'" is not recognized by Emmett.');c[a]=n[a]}this._handlers[h].push(c)}}else if(t&&"object"==typeof t&&!Array.isArray(t))for(h in t)o.prototype.on.call(this,h,t[h],r);else{if("function"!=typeof t)throw new Error("Wrong arguments.");c={handler:t};for(a in n||{}){if(!e[a])throw new Error('The option "'+a+'" is not recognized by Emmett.');c[a]=n[a]}this._handlersAll.push(c)}return this},o.prototype.once=function(t,e,r){if("function"==typeof e)r=r||{},r.once=!0,this.on(t,e,r);else{if((!t||"object"!=typeof t||Array.isArray(t))&&"function"!=typeof t)throw new Error("Wrong arguments.");e=e||{},e.once=!0,this.on(t,e)}return this},o.prototype.off=function(t,e){var r,n,o,i,s,a,h,u="string"==typeof t?[t]:t;if(1===arguments.length&&"function"==typeof u){e=arguments[0];for(s in this._handlers){for(a=[],r=0,n=this._handlers[s].length;r!==n;r+=1)this._handlers[s][r].handler!==e&&a.push(this._handlers[s][r]);this._handlers[s]=a}for(a=[],r=0,n=this._handlersAll.length;r!==n;r+=1)this._handlersAll[r].handler!==e&&a.push(this._handlersAll[r]);this._handlersAll=a}else if(2===arguments.length)for(r=0,n=u.length;r!==n;r+=1){if(h=u[r],this._handlers[h]){for(a=[],o=0,i=this._handlers[h].length;o!==i;o+=1)this._handlers[h][o].handler!==e&&a.push(this._handlers[h][o]);this._handlers[h]=a}this._handlers[h]&&0===this._handlers[h].length&&delete this._handlers[h]}return this},o.prototype.unbindAll=function(){var t;this._handlersAll=[];for(t in this._handlers)delete this._handlers[t];return this},o.prototype.emit=function(t,e){var r,n,o,i,s,a,h,u,c,l="string"==typeof t?[t]:t;if(!this._enabled)return this;for(e=void 0===e?{}:e,r=0,n=l.length;r!==n;r+=1)if(c=l[r],u=(this._handlers[c]||[]).concat(this._handlersAll),u.length){for(a={type:c,data:e||{},target:this},s=[],o=0,i=u.length;o!==i;o+=1)u[o].handler.call("scope"in u[o]?u[o].scope:this,a),u[o].once||s.push(u[o]);this._handlers[c]=s}for(r=0,n=this._children.length;r!==n;r+=1)h=this._children[r],h.emit.apply(h,arguments);return this},o.prototype.child=function(){var t=this,e=new o;return e.on("emmett:kill",function(){if(t._children)for(var r=0,n=t._children.length;n>r;r++)if(t._children[r]===e){t._children.splice(r,1);break}}),this._children.push(e),e},o.prototype.kill=function(){if(this.emit("emmett:kill"),this.unbindAll(),this._handlers=null,this._handlersAll=null,this._enabled=!1,this._children)for(var t=0,e=this._children.length;e>t;t++)this._children[t].kill();this._children=null},o.prototype.disable=function(){return this._enabled=!1,this},o.prototype.enable=function(){return this._enabled=!0,this},o.version="2.1.1","undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=o),n.Emitter=o):"function"==typeof t&&t.amd?t("emmett",[],function(){return o}):this.Emitter=o}).call(this)},{}],5:[function(e,r,n){!function(){"use strict";function e(t){function e(t,o){var s,a,h,u,c,l,f,p,d=!1,y=!1,g=r.get(t);if("string"===r.get(o)){for(s=o.replace(/^[\?\!]/,"").split(/\|/),h=s.length,a=0;h>a;a++)if(i.indexOf(s[a])<0&&!(s[a]in n))throw new Error("Invalid type.");if(o.match(/^\?/)&&(d=!0),o.replace(/^\?/,"").match(/^\!/)&&(y=!0),y&&d)throw new Error("Invalid type.");for(a in s)if(n[s[a]]&&("function"==typeof n[s[a]].type?n[s[a]].type.call(r,t)===!0:!e(t,n[s[a]].type)))return y?(c=new Error,c.message='Expected a "'+o+'" but found a "'+s[a]+'".',c.expected=o,c.type=s[a],c.value=t,c):null;return null===t||void 0===t?y||d?null:(c=new Error,c.message='Expected a "'+o+'" but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c):(f=~s.indexOf("*"),p=~s.indexOf(g),y&&(f||p)?(c=new Error,c.message='Expected a "'+o+'" but found a "'+(p?g:"*")+'".',c.type=p?g:"*",c.expected=o,c.value=t,c):y||f||p?null:(c=new Error,c.message='Expected a "'+o+'" but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c))}if("object"===r.get(o)){if("object"!==g)return c=new Error,c.message='Expected an object but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c;for(u in o)if(l=e(t[u],o[u]))return c=l,c.path=c.path?[u].concat(c.path):[u],c;for(u in t)if(void 0===o[u])return c=new Error,c.message='Unexpected key "'+u+'".',c.type=g,c.value=t,c;return null}if("array"===r.get(o)){if(1!==o.length)throw new Error("Invalid type.");if("array"!==g)return c=new Error,c.message='Expected an array but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c;for(h=t.length,a=0;h>a;a++)if(l=e(t[a],o[0]))return c=l,c.path=c.path?[a].concat(c.path):[a],c;return null}throw new Error("Invalid type.")}var r=this,n={};if(this.add=function(t,e){var r,o,s,a,h,u;if(1===arguments.length){if("object"!==this.get(t))throw new Error("If types.add is called with one argument, this one has to be an object.");r=t,a=r.id,u=r.type}else{if(2!==arguments.length)throw new Error("types.add has to be called with one or two arguments.");if("string"!=typeof t||!t)throw new Error("If types.add is called with more than one argument, the first one must be the string id.");a=t,u=e}if("string"!==this.get(a)||0===a.length)throw new Error("A type requires an string id.");if(void 0!==n[a]&&"proto"!==n[a])throw new Error('The type "'+a+'" already exists.');if(~i.indexOf(a))throw new Error('"'+a+'" is a reserved type name.');n[a]=1,s=(r||{}).proto||[],s=Array.isArray(s)?s:[s],h={};for(o in s)void 0===n[s[o]]&&(n[s[o]]=1,h[s[o]]=1);if("function"!==this.get(u)&&!this.isValid(u))throw new Error("A type requires a valid definition. This one can be a preexistant type or else a function testing given objects.");if(n[a]=void 0===r?{id:a,type:u}:{},void 0!==r)for(o in r)n[a][o]=r[o];for(o in h)o!==a&&delete n[o];return this},this.has=function(t){return!!n[t]},this.get=function(t){return null===t||void 0===t?String(t):o[Object.prototype.toString.call(t)]||"object"},this.check=function(t,r,n){var o=e(t,r);if(n&&o)throw o;return!o},this.isValid=function(t){var e,r,o;if("string"===this.get(t)){e=t.replace(/^[\?\!]/,"").split(/\|/);for(o in e)if(i.indexOf(e[o])<0&&!(e[o]in n))return!1;return!0}if("object"===this.get(t)){for(r in t)if(!this.isValid(t[r]))return!1;return!0}return"array"===this.get(t)&&1===t.length?this.isValid(t[0]):!1},this.add("type",function(t){return this.isValid(t)}.bind(this)),this.add("primitive",function(t){return!t||!(t instanceof Object||"object"==typeof t)}),t=t||{},"object"!==this.get(t))throw Error("Invalid argument.");for(var s in t)this.add(s,t[s])}var o={},i=["*"];!function(){var t,e,r=["Arguments","Boolean","Number","String","Function","Array","Date","RegExp","Object"];for(t in r)e=r[t],i.push(e.toLowerCase()),o["[object "+e+"]"]=e.toLowerCase()}();var s=e;e.call(s),Object.defineProperty(s,"version",{value:"0.3.1"}),"undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=s),n.types=s):"function"==typeof t&&t.amd?t("typology",[],function(){return s}):this.types=s}(this)},{}],6:[function(t,e){function r(t,e){if(!(this instanceof r))return new r(t,e);if(!u.check(t,"object|array"))throw Error("Baobab: invalid data.");if(o.call(this),this.options=s.shallowMerge(l,e),this._cloner=this.options.cloningFunction||s.deepClone,this._futureUpdate={},this._willUpdate=!1,this._history=[],this._registeredCursors={},this.typology=this.options.typology?u.check(this.options.typology,"typology")?this.options.typology:new i(this.options.typology):new i,this.validate=this.options.validate||null,this.validate)try{this.typology.check(t,this.validate,!0)}catch(n){throw n.message="/"+n.path.join("/")+": "+n.message,n}this.data=this._cloner(t),this.mixin=c.baobab(this)}var n=t("./cursor.js"),o=t("emmett"),i=t("typology"),s=t("./helpers.js"),a=t("./update.js"),h=t("./merge.js"),u=t("./typology.js"),c=t("./mixins.js"),l=t("../defaults.json");s.inherits(r,o),r.prototype._stack=function(t){var e=this;if(!u.check(t,"object"))throw Error("Baobab.update: wrong specification.");return this._futureUpdate=h(t,this._futureUpdate),this.options.autoCommit?this.options.asynchronous?(this._willUpdate||(this._willUpdate=!0,s.later(function(){e.commit()})),this):this.commit():this},r.prototype._archive=function(){if(!(this.options.maxHistory<=0)){var t={data:this._cloner(this.data)};return this._history.length===this.options.maxHistory&&this._history.pop(),this._history.unshift(t),t}},r.prototype.commit=function(t){var e;if(t)this.data=t.data,e=t.log;else{this.options.shiftReferences&&(this.data=s.shallowClone(this.data));var r=this._archive();e=a(this.data,this._futureUpdate,this.options),r&&(r.log=e)}if(this.validate){var n,o,i=[],h=e.length;for(o=0;h>o;o++)if(n=s.getIn(this.validate,e[o]))try{this.typology.check(this.get(e[o]),n,!0)}catch(u){u.path=e[o].concat(u.path||[]),i.push(u)}i.length&&this.emit("invalid",{errors:i})}return this.emit("update",{log:e}),this._futureUpdate={},this._willUpdate=!1,this},r.prototype.select=function(t){if(arguments.length>1&&(t=s.arrayOf(arguments)),!u.check(t,"path"))throw Error("Baobab.select: invalid path.");t="array"!==u.get(t)?[t]:t;var e,r=t.some(function(t){return u.check(t,"complexStep")});if(r&&(e=s.solvePath(this.data,t)),this.options.cursorSingletons){var o=t.join("λ");if(this._registeredCursors[o])return this._registeredCursors[o];var i=new n(this,t,e);return this._registeredCursors[o]=i,i}return new n(this,t)},r.prototype.reference=function(t){if(arguments.length>1&&(t=s.arrayOf(arguments)),!u.check(t,"path"))throw Error("Baobab.get: invalid path.");return s.getIn(this.data,u.check(t,"string|number")?[t]:t)},r.prototype.get=function(){var t=this.reference.apply(this,arguments);return this.options.clone?this._cloner(t):t},r.prototype.clone=function(){return this._cloner(this.reference.apply(this,arguments))},r.prototype.set=function(t,e){if(arguments.length<2)throw Error("Baobab.set: expects a key and a value.");var r={};return r[t]={$set:e},this.update(r)},r.prototype.update=function(t){return this._stack(t)},r.prototype.hasHistory=function(){return!!this._history.length},r.prototype.getHistory=function(){return this._history},r.prototype.undo=function(){if(!this.hasHistory())throw Error("Baobab.undo: no history recorded, cannot undo.");var t=this._history.shift();this.commit(t)},u.add("baobab",function(t){return t instanceof r}),r.prototype.toJSON=function(){return this.reference()},e.exports=r},{"../defaults.json":1,"./cursor.js":8,"./helpers.js":9,"./merge.js":10,"./mixins.js":11,"./typology.js":12,"./update.js":13,emmett:4,typology:5}],7:[function(t,e){function r(t,e){e.on("update",t.cursorListener)}function n(t){var e=this;if(arguments.length<2)throw Error("baobab.Combination: not enough arguments.");var n=arguments[1],a=s.arrayOf(arguments).slice(2);if(n instanceof Array&&(a=n.slice(1),n=n[0]),!i.check(n,"cursor"))throw Error("baobab.Combination: argument should be a cursor.");if("or"!==t&&"and"!==t)throw Error("baobab.Combination: invalid operator.");o.call(this),this.cursors=[n],this.operators=[],this.root=n.root,this.updates=new Array(this.cursors.length),this.cursorListener=function(){e.updates[e.cursors.indexOf(this)]=!0},this.treeListener=function(){var t,r,n=e.updates[0];for(t=1,r=e.cursors.length;r>t;t++)n="or"===e.operators[t-1]?n||e.updates[t]:n&&e.updates[t];n&&e.emit("update"),e.updates=new Array(e.cursors.length)},this.root.on("update",this.treeListener),r(this,n),a.forEach(function(e){this[t](e)},this)}var o=t("emmett"),i=t("./typology.js"),s=t("./helpers.js");s.inherits(n,o),n.prototype.or=function(t){if(!i.check(t,"cursor"))throw Error("baobab.Combination.or: argument should be a cursor.");if(~this.cursors.indexOf(t))throw Error("baobab.Combination.or: cursor already in combination.");return this.cursors.push(t),this.operators.push("or"),this.updates.length++,r(this,t),this},n.prototype.and=function(t){if(!i.check(t,"cursor"))throw Error("baobab.Combination.and: argument should be a cursor.");if(~this.cursors.indexOf(t))throw Error("baobab.Combination.and: cursor already in combination.");return this.cursors.push(t),this.operators.push("and"),this.updates.length++,r(this,t),this},n.prototype.release=function(){this.unbindAll(),this.cursors.forEach(function(t){t.off("update",this.cursorListener)},this),this.root.off("update",this.treeListener),this.cursors=null,this.operators=null,this.root=null,this.updates=null},e.exports=n},{"./helpers.js":9,"./typology.js":12,emmett:4}],8:[function(t,e){function r(t,e,r){var o=this;n.call(this),e=e||[],this.root=t,this.path=e,this.relevant=void 0!==this.reference(),this.complexPath=!!r,this.solvedPath=this.complexPath?r:this.path,this.updateHandler=function(t){var e,r,n,i,a,h,u=t.data.log,c=!1;if(o.complexPath&&(o.solvedPath=s.solvePath(o.root.data,o.path)),this._handlers.update.length||this._handlersAll.length){if(!o.path.length)return o.emit("update");t:for(a=0,n=u.length;n>a;a++)for(e=u[a],h=0,i=e.length;i>h&&(r=e[h],r===o.solvedPath[h]);h++)if(h+1===i||h+1===o.solvedPath.length){c=!0;break t}var l=void 0!==o.reference();o.relevant?l&&c?o.emit("update"):(o.emit("irrelevant"),o.relevant=!1):l&&c&&(o.emit("relevant"),o.emit("update"),o.relevant=!0)}},this.root.on("update",this.updateHandler),this.mixin=i.cursor(this)}var n=t("emmett"),o=t("./combination.js"),i=t("./mixins.js"),s=t("./helpers.js"),a=t("./typology.js");s.inherits(r,n),r.prototype._stack=function(t){return this.root._stack(s.pathObject(this.solvedPath,t)),this},r.prototype.isRoot=function(){return!this.path.length},r.prototype.isLeaf=function(){return a.check(this.reference(),"primitive")},r.prototype.isBranch=function(){return!this.isLeaf()&&!this.isRoot()},r.prototype.select=function(t){if(arguments.length>1&&(t=s.arrayOf(arguments)),!a.check(t,"path"))throw Error("baobab.Cursor.select: invalid path.");return this.root.select(this.path.concat(t))},r.prototype.up=function(){return this.solvedPath&&this.solvedPath.length?this.root.select(this.path.slice(0,-1)):null},r.prototype.left=function(){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.root.select(this.solvedPath.slice(0,-1).concat(t-1)):null},r.prototype.leftmost=function(){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.root.select(this.solvedPath.slice(0,-1).concat(0))},r.prototype.right=function(){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().reference().length?null:this.root.select(this.solvedPath.slice(0,-1).concat(t+1))},r.prototype.rightmost=function(){var t=+this.solvedPath[this.solvedPath.length-1];if(isNaN(t))throw Error("baobab.Cursor.right: cannot go right on a non-list type.");var e=this.up().reference();return this.root.select(this.solvedPath.slice(0,-1).concat(e.length-1))},r.prototype.down=function(){+this.solvedPath[this.solvedPath.length-1];return this.reference()instanceof Array?this.root.select(this.solvedPath.concat(0)):null},r.prototype.get=function(t){return arguments.length>1&&(t=s.arrayOf(arguments)),this.root.get(a.check(t,"step")?this.solvedPath.concat(t):this.solvedPath)},r.prototype.reference=function(t){return arguments.length>1&&(t=s.arrayOf(arguments)),this.root.reference(a.check(t,"step")?this.solvedPath.concat(t):this.solvedPath)},r.prototype.clone=function(t){return arguments.length>1&&(t=s.arrayOf(arguments)),this.root.clone(a.check(t,"step")?this.solvedPath.concat(t):this.solvedPath)},r.prototype.set=function(t,e){if(arguments.length<2)throw Error("baobab.Cursor.set: expecting at least key/value.");var r={};return r[t]={$set:e},this.update(r)},r.prototype.edit=function(t){return this.update({$set:t})},r.prototype.apply=function(t){if("function"!=typeof t)throw Error("baobab.Cursor.apply: argument is not a function.");return this.update({$apply:t})},r.prototype.thread=function(t){if("function"!=typeof t)throw Error("baobab.Cursor.thread: argument is not a function.");return this.update({$thread:t})},r.prototype.push=function(t){if(!(this.reference()instanceof Array))throw Error("baobab.Cursor.push: trying to push to non-array value.");return this.update(arguments.length>1?{$push:s.arrayOf(arguments)}:{$push:t})},r.prototype.unshift=function(t){if(!(this.reference()instanceof Array))throw Error("baobab.Cursor.push: trying to push to non-array value.");return this.update(arguments.length>1?{$unshift:s.arrayOf(arguments)}:{$unshift:t})},r.prototype.merge=function(t){if(!a.check(t,"object"))throw Error("baobab.Cursor.merge: trying to merge a non-object.");if(!a.check(this.reference(),"object"))throw Error("baobab.Cursor.merge: trying to merge into a non-object.");this.update({$merge:t})},r.prototype.update=function(t){return this._stack(t)},r.prototype.or=function(t){return new o("or",this,t)},r.prototype.and=function(t){return new o("and",this,t)},r.prototype.release=function(){this.root.off("update",this.updateHandler),this.root=null,this.unbindAll()},r.prototype.toJSON=function(){return this.reference()},a.add("cursor",function(t){return t instanceof r}),e.exports=r},{"./combination.js":7,"./helpers.js":9,"./mixins.js":11,"./typology.js":12,emmett:4}],9:[function(t,e){(function(r){function n(t){return Array.prototype.slice.call(t)}function o(t,e){var r,n={};for(r in t)n[r]=t[r];for(r in e)n[r]=e[r];return n}function i(t){if(!(t&&t instanceof Object))return t;if("array"===m.get(t))return t.slice(0);if("date"===m.get(t))return new Date(t.getTime());if("object"===m.get(t)){var e,r={};for(e in t)r[e]=t[e];return r}return t}function s(t){if(!(t&&t instanceof Object))return t;if("array"===m.get(t)){var e,r,n=[];for(e=0,r=t.length;r>e;e++)n.push(s(t[e]));return n}if("date"===m.get(t))return new Date(t.getTime());if("object"===m.get(t)){var o,i={};for(o in t)i[o]=s(t[o]);return i}return t}function a(t,e){return function(r){return e(t(r))}}function h(t,e){var r,n;for(r=0,n=t.length;n>r;r++)if(e(t[r]))return t[r]}function u(t,e){var r,n;for(r=0,n=t.length;n>r;r++)if(e(t[r]))return r;return-1}function c(t,e){var r,n=!0;for(r in e)if("object"===m.get(e[r]))n=n&&c(t[r]);else if("array"===m.get(e[r]))n=n&&!!~e[r].indexOf(t[r]);else if(t[r]!==e[r])return!1;return n}function l(t,e){return h(t,function(t){return c(t,e)})}function f(t,e){return indexOf(t,function(t){return c(t,e)})}function p(t,e){e=e||[];var r,n,o=t;for(r=0,n=e.length;n>r;r++){if(!o)return;if("function"==typeof e[r]){if("array"!==m.get(o))return;o=h(o,e[r])}else if("object"==typeof e[r]){if("array"!==m.get(o))return;o=l(o,e[r])}else o=o[e[r]]}return o}function d(t,e){var r,n,o,i=[],s=t;for(n=0,o=e.length;o>n;n++){if(!s)return null;if("function"==typeof e[n]){if("array"!==m.get(s))return;r=u(s,e[n]),i.push(r),s=s[r]}else if("object"==typeof e[n]){if("array"!==m.get(s))return;r=u(f(s,e[n])),i.push(r),s=s[r]}else i.push(e[n]),s=s[e[n]]}return i}function y(t,e){var r,n=t.length,o={},i=o;for(n||(o=e),r=0;n>r;r++)i[t[r]]=r+1===n?e:{},i=i[t[r]];return o}function g(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}var m=t("typology"),b="undefined"==typeof window?r.nextTick:"requestAnimationFrame"in window?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,0)};e.exports={arrayOf:n,deepClone:s,shallowClone:i,shallowMerge:o,compose:a,getIn:p,inherits:g,later:b,pathObject:y,solvePath:d}}).call(this,t("_process"))},{_process:3,typology:5}],10:[function(t,e){function r(t,e){return e in(t||{})}function n(t,e,n){return r(t,n)&&r(e,n)}function o(){var t,e,r,a,h={},u=arguments.length;for(r=u-1;r>=0;r--)if(arguments[r].$set)delete h.$apply,delete h.$merge,h.$set=arguments[r].$set;else if(arguments[r].$merge)delete h.$set,delete h.$apply,h.$merge=arguments[r].$merge;else if(arguments[r].$apply)delete h.$set,delete h.$merge,h.$apply=arguments[r].$apply;else if(arguments[r].$chain)delete h.$set,delete h.$merge,h.$apply=h.$apply?s.compose(h.$apply,arguments[r].$chain):arguments[r].$chain;else for(a in arguments[r])t=h[a],e=arguments[r][a],t&&i.check(e,"object")?n(t,e,"$push")?t.$push=i.check(t.$push,"array")?t.$push.concat(e.$push):[t.$push].concat(e.$push):n(t,e,"$unshift")?t.$unshift=i.check(e.$unshift,"array")?e.$unshift.concat(t.$unshift):[e.$unshift].concat(t.$unshift):h[a]=o(e,t):h[a]=e;return h}var i=t("typology"),s=t("./helpers.js");e.exports=o},{"./helpers.js":9,typology:5}],11:[function(t,e){var r=t("./typology.js"),n=t("./combination.js");e.exports={baobab:function(t){return{mixins:[{getInitialState:function(){if(this.tree=t,this.__type=null,this.cursor&&this.cursors)throw Error("baobab.mixin: you cannot have both `component.cursor` and `component.cursors`. Please make up your mind.");if(this.__updateHandler=function(){this.setState(this.__getCursorData())}.bind(this),this.cursor){if(!r.check(this.cursor,"string|number|array|cursor"))throw Error("baobab.mixin.cursor: invalid data (cursor, string or array).");r.check(this.cursor,"cursor")||(this.cursor=t.select(this.cursor)),this.__getCursorData=function(){return{cursor:this.cursor.get()}}.bind(this),this.__type="single"}else if(this.cursors){if(!r.check(this.cursors,"object|array"))throw Error("baobab.mixin.cursor: invalid data (object or array).");if(r.check(this.cursors,"array"))this.cursors=this.cursors.map(function(e){return r.check(e,"cursor")?e:t.select(e)}),this.__getCursorData=function(){return{cursors:this.cursors.map(function(t){return t.get()})}}.bind(this),this.__type="array";else{for(var e in this.cursors)r.check(this.cursors[e],"cursor")||(this.cursors[e]=t.select(this.cursors[e]));this.__getCursorData=function(){var t={};for(e in this.cursors)t[e]=this.cursors[e].get();return{cursors:t}}.bind(this),this.__type="object"}}return this.__getCursorData()},componentDidMount:function(){"single"===this.__type?this.cursor.on("update",this.__updateHandler):"array"===this.__type?(this.__combination=new n("or",this.cursors),this.__combination.on("update",this.__updateHandler)):"object"===this.__type&&(this.__combination=new n("or",Object.keys(this.cursors).map(function(t){return this.cursors[t]},this)),this.__combination.on("update",this.__updateHandler))},componentWillUnmount:function(){"single"===this.__type?this.cursor.off("update",this.__updateHandler):this.__combination.release()}}].concat(t.options.mixins)}},cursor:function(t){return{mixins:[{getInitialState:function(){return this.cursor=t,this.__updateHandler=function(){this.setState({cursor:this.cursor.get()})}.bind(this),{cursor:this.cursor.get()}},componentDidMount:function(){this.cursor.on("update",this.__updateHandler)},componentWillUnmount:function(){this.cursor.off("update",this.__updateHandler)}}].concat(t.root.options.mixins)}}}},{"./combination.js":7,"./typology.js":12}],12:[function(t,e){var r=t("typology"),n=new r({complexStep:"function|object",step:"string|number|array|function|object",path:function(t){return this.check(t,"?string|number|function|object")||this.check(t,["string|number|function|object"])},typology:function(t){return t instanceof r}});e.exports=n},{typology:5}],13:[function(t,e){function r(t,e){var r=new Error("precursors.update: "+e+" at path /"+t.toString());return r.path=t,r}function n(t,e,n){n=n||{};var a={};return function h(t,e,u){u=u||[];var c,l,f,p,d=u.join("λ");for(f in e)if(s[f])switch(p=e[f],a[d]=!0,f){case"$push":if(!o.check(t,"array"))throw r(u,"using command $push to a non array");o.check(p,"array")?t.push.apply(t,p):t.push(p);break;case"$unshift":if(!o.check(t,"array"))throw r(u,"using command $unshift to a non array");o.check(p,"array")?t.unshift.apply(t,p):t.unshift(p)}else if(l=d?d+"λ"+f:f,"$set"in(e[f]||{}))p=e[f].$set,a[l]=!0,t[f]=p;else if("$apply"in(e[f]||{})){if(c=e[f].$apply,"function"!=typeof c)throw r(u.concat(f),"using command $apply with a non function");a[l]=!0,t[f]=c.call(null,t[f])}else if("$merge"in(e[f]||{})){if(p=e[f].$merge,!o.check(t[f],"object"))throw r(u.concat(f),"using command $merge on a non-object");a[l]=!0,t[f]=i.shallowMerge(t[f],p)}else if(n.shiftReferences&&("$push"in(e[f]||{})||"$unshift"in(e[f]||{}))){if("$push"in(e[f]||{})){if(p=e[f].$push,!o.check(t[f],"array"))throw r(u.concat(f),"using command $push to a non array");t[f]=t[f].concat(p)}if("$unshift"in(e[f]||{})){if(p=e[f].$unshift,!o.check(t[f],"array"))throw r(u.concat(f),"using command $unshift to a non array");t[f]=(p instanceof Array?p:[p]).concat(t[f])}a[l]=!0}else"undefined"==typeof t[f]&&(t[f]={}),n.shiftReferences&&(t[f]=i.shallowClone(t[f])),h(t[f],e[f],u.concat(f))}(t,e),Object.keys(a).map(function(t){return t.split("λ")})}var o=t("./typology.js"),i=t("./helpers.js"),s={};["$set","$push","$unshift","$apply","$merge"].forEach(function(t){s[t]=!0}),e.exports=n},{"./helpers.js":9,"./typology.js":12}]},{},[2])(2)}); \ No newline at end of file +/* baobab.js - Version: 0.3.1 - 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;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Baobab=t()}}(function(){var t;return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var h="function"==typeof require&&require;if(!a&&h)return h(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){var r=t[s][1][e];return o(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s0)){var r=n.shift();r()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}):function(t){setTimeout(t,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=r,n.addListener=r,n.once=r,n.off=r,n.removeListener=r,n.removeAllListeners=r,n.emit=r,n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(e,r,n){(function(){"use strict";var e={once:"boolean",scope:"object"},o=function(){this._enabled=!0,this._children=[],this._handlers={},this._handlersAll=[]};o.prototype.on=function(t,r,n){var i,s,a,h,u,c;if("function"==typeof r){for(u="string"==typeof t?[t]:t,i=0,s=u.length;i!==s;i+=1)if(h=u[i]){this._handlers[h]||(this._handlers[h]=[]),c={handler:r};for(a in n||{}){if(!e[a])throw new Error('The option "'+a+'" is not recognized by Emmett.');c[a]=n[a]}this._handlers[h].push(c)}}else if(t&&"object"==typeof t&&!Array.isArray(t))for(h in t)o.prototype.on.call(this,h,t[h],r);else{if("function"!=typeof t)throw new Error("Wrong arguments.");c={handler:t};for(a in n||{}){if(!e[a])throw new Error('The option "'+a+'" is not recognized by Emmett.');c[a]=n[a]}this._handlersAll.push(c)}return this},o.prototype.once=function(t,e,r){if("function"==typeof e)r=r||{},r.once=!0,this.on(t,e,r);else{if((!t||"object"!=typeof t||Array.isArray(t))&&"function"!=typeof t)throw new Error("Wrong arguments.");e=e||{},e.once=!0,this.on(t,e)}return this},o.prototype.off=function(t,e){var r,n,o,i,s,a,h,u="string"==typeof t?[t]:t;if(1===arguments.length&&"function"==typeof u){e=arguments[0];for(s in this._handlers){for(a=[],r=0,n=this._handlers[s].length;r!==n;r+=1)this._handlers[s][r].handler!==e&&a.push(this._handlers[s][r]);this._handlers[s]=a}for(a=[],r=0,n=this._handlersAll.length;r!==n;r+=1)this._handlersAll[r].handler!==e&&a.push(this._handlersAll[r]);this._handlersAll=a}else if(2===arguments.length)for(r=0,n=u.length;r!==n;r+=1){if(h=u[r],this._handlers[h]){for(a=[],o=0,i=this._handlers[h].length;o!==i;o+=1)this._handlers[h][o].handler!==e&&a.push(this._handlers[h][o]);this._handlers[h]=a}this._handlers[h]&&0===this._handlers[h].length&&delete this._handlers[h]}return this},o.prototype.unbindAll=function(){var t;this._handlersAll=[];for(t in this._handlers)delete this._handlers[t];return this},o.prototype.emit=function(t,e){var r,n,o,i,s,a,h,u,c,l="string"==typeof t?[t]:t;if(!this._enabled)return this;for(e=void 0===e?{}:e,r=0,n=l.length;r!==n;r+=1)if(c=l[r],u=(this._handlers[c]||[]).concat(this._handlersAll),u.length){for(a={type:c,data:e||{},target:this},s=[],o=0,i=u.length;o!==i;o+=1)u[o].handler.call("scope"in u[o]?u[o].scope:this,a),u[o].once||s.push(u[o]);this._handlers[c]=s}for(r=0,n=this._children.length;r!==n;r+=1)h=this._children[r],h.emit.apply(h,arguments);return this},o.prototype.child=function(){var t=this,e=new o;return e.on("emmett:kill",function(){if(t._children)for(var r=0,n=t._children.length;n>r;r++)if(t._children[r]===e){t._children.splice(r,1);break}}),this._children.push(e),e},o.prototype.kill=function(){if(this.emit("emmett:kill"),this.unbindAll(),this._handlers=null,this._handlersAll=null,this._enabled=!1,this._children)for(var t=0,e=this._children.length;e>t;t++)this._children[t].kill();this._children=null},o.prototype.disable=function(){return this._enabled=!1,this},o.prototype.enable=function(){return this._enabled=!0,this},o.version="2.1.1","undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=o),n.Emitter=o):"function"==typeof t&&t.amd?t("emmett",[],function(){return o}):this.Emitter=o}).call(this)},{}],5:[function(e,r,n){!function(){"use strict";function e(t){function e(t,o){var s,a,h,u,c,l,f,p,d=!1,y=!1,g=r.get(t);if("string"===r.get(o)){for(s=o.replace(/^[\?\!]/,"").split(/\|/),h=s.length,a=0;h>a;a++)if(i.indexOf(s[a])<0&&!(s[a]in n))throw new Error("Invalid type.");if(o.match(/^\?/)&&(d=!0),o.replace(/^\?/,"").match(/^\!/)&&(y=!0),y&&d)throw new Error("Invalid type.");for(a in s)if(n[s[a]]&&("function"==typeof n[s[a]].type?n[s[a]].type.call(r,t)===!0:!e(t,n[s[a]].type)))return y?(c=new Error,c.message='Expected a "'+o+'" but found a "'+s[a]+'".',c.expected=o,c.type=s[a],c.value=t,c):null;return null===t||void 0===t?y||d?null:(c=new Error,c.message='Expected a "'+o+'" but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c):(f=~s.indexOf("*"),p=~s.indexOf(g),y&&(f||p)?(c=new Error,c.message='Expected a "'+o+'" but found a "'+(p?g:"*")+'".',c.type=p?g:"*",c.expected=o,c.value=t,c):y||f||p?null:(c=new Error,c.message='Expected a "'+o+'" but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c))}if("object"===r.get(o)){if("object"!==g)return c=new Error,c.message='Expected an object but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c;for(u in o)if(l=e(t[u],o[u]))return c=l,c.path=c.path?[u].concat(c.path):[u],c;for(u in t)if(void 0===o[u])return c=new Error,c.message='Unexpected key "'+u+'".',c.type=g,c.value=t,c;return null}if("array"===r.get(o)){if(1!==o.length)throw new Error("Invalid type.");if("array"!==g)return c=new Error,c.message='Expected an array but found a "'+g+'".',c.expected=o,c.type=g,c.value=t,c;for(h=t.length,a=0;h>a;a++)if(l=e(t[a],o[0]))return c=l,c.path=c.path?[a].concat(c.path):[a],c;return null}throw new Error("Invalid type.")}var r=this,n={};if(this.add=function(t,e){var r,o,s,a,h,u;if(1===arguments.length){if("object"!==this.get(t))throw new Error("If types.add is called with one argument, this one has to be an object.");r=t,a=r.id,u=r.type}else{if(2!==arguments.length)throw new Error("types.add has to be called with one or two arguments.");if("string"!=typeof t||!t)throw new Error("If types.add is called with more than one argument, the first one must be the string id.");a=t,u=e}if("string"!==this.get(a)||0===a.length)throw new Error("A type requires an string id.");if(void 0!==n[a]&&"proto"!==n[a])throw new Error('The type "'+a+'" already exists.');if(~i.indexOf(a))throw new Error('"'+a+'" is a reserved type name.');n[a]=1,s=(r||{}).proto||[],s=Array.isArray(s)?s:[s],h={};for(o in s)void 0===n[s[o]]&&(n[s[o]]=1,h[s[o]]=1);if("function"!==this.get(u)&&!this.isValid(u))throw new Error("A type requires a valid definition. This one can be a preexistant type or else a function testing given objects.");if(n[a]=void 0===r?{id:a,type:u}:{},void 0!==r)for(o in r)n[a][o]=r[o];for(o in h)o!==a&&delete n[o];return this},this.has=function(t){return!!n[t]},this.get=function(t){return null===t||void 0===t?String(t):o[Object.prototype.toString.call(t)]||"object"},this.check=function(t,r,n){var o=e(t,r);if(n&&o)throw o;return!o},this.isValid=function(t){var e,r,o;if("string"===this.get(t)){e=t.replace(/^[\?\!]/,"").split(/\|/);for(o in e)if(i.indexOf(e[o])<0&&!(e[o]in n))return!1;return!0}if("object"===this.get(t)){for(r in t)if(!this.isValid(t[r]))return!1;return!0}return"array"===this.get(t)&&1===t.length?this.isValid(t[0]):!1},this.add("type",function(t){return this.isValid(t)}.bind(this)),this.add("primitive",function(t){return!t||!(t instanceof Object||"object"==typeof t)}),t=t||{},"object"!==this.get(t))throw Error("Invalid argument.");for(var s in t)this.add(s,t[s])}var o={},i=["*"];!function(){var t,e,r=["Arguments","Boolean","Number","String","Function","Array","Date","RegExp","Object"];for(t in r)e=r[t],i.push(e.toLowerCase()),o["[object "+e+"]"]=e.toLowerCase()}();var s=e;e.call(s),Object.defineProperty(s,"version",{value:"0.3.1"}),"undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=s),n.types=s):"function"==typeof t&&t.amd?t("typology",[],function(){return s}):this.types=s}(this)},{}],6:[function(t,e){function r(t,e){if(!(this instanceof r))return new r(t,e);if(!u.check(t,"object|array"))throw Error("Baobab: invalid data.");if(o.call(this),this.options=s.shallowMerge(l,e),this._cloner=this.options.cloningFunction||s.deepClone,this._futureUpdate={},this._willUpdate=!1,this._history=[],this._registeredCursors={},this.typology=this.options.typology?u.check(this.options.typology,"typology")?this.options.typology:new i(this.options.typology):new i,this.validate=this.options.validate||null,this.validate)try{this.typology.check(t,this.validate,!0)}catch(n){throw n.message="/"+n.path.join("/")+": "+n.message,n}this.data=this._cloner(t),this.mixin=c.baobab(this)}var n=t("./cursor.js"),o=t("emmett"),i=t("typology"),s=t("./helpers.js"),a=t("./update.js"),h=t("./merge.js"),u=t("./typology.js"),c=t("./mixins.js"),l=t("../defaults.json");s.inherits(r,o),r.prototype._stack=function(t){var e=this;if(!u.check(t,"object"))throw Error("Baobab.update: wrong specification.");return this._futureUpdate=h(t,this._futureUpdate),this.options.autoCommit?this.options.asynchronous?(this._willUpdate||(this._willUpdate=!0,s.later(function(){e.commit()})),this):this.commit():this},r.prototype._archive=function(){if(!(this.options.maxHistory<=0)){var t={data:this._cloner(this.data)};return this._history.length===this.options.maxHistory&&this._history.pop(),this._history.unshift(t),t}},r.prototype.commit=function(t){var e;if(t)this.data=t.data,e=t.log;else{this.options.shiftReferences&&(this.data=s.shallowClone(this.data));var r=this._archive();e=a(this.data,this._futureUpdate,this.options),r&&(r.log=e)}if(this.validate){var n,o,i=[],h=e.length;for(o=0;h>o;o++)if(n=s.getIn(this.validate,e[o]))try{this.typology.check(this.get(e[o]),n,!0)}catch(u){u.path=e[o].concat(u.path||[]),i.push(u)}i.length&&this.emit("invalid",{errors:i})}return this.emit("update",{log:e}),this._futureUpdate={},this._willUpdate=!1,this},r.prototype.select=function(t){if(arguments.length>1&&(t=s.arrayOf(arguments)),!u.check(t,"path"))throw Error("Baobab.select: invalid path.");t="array"!==u.get(t)?[t]:t;var e,r=t.some(function(t){return u.check(t,"complexStep")});if(r&&(e=s.solvePath(this.data,t)),this.options.cursorSingletons){var o=t.join("λ");if(this._registeredCursors[o])return this._registeredCursors[o];var i=new n(this,t,e);return this._registeredCursors[o]=i,i}return new n(this,t)},r.prototype.reference=function(t){if(arguments.length>1&&(t=s.arrayOf(arguments)),!u.check(t,"path"))throw Error("Baobab.get: invalid path.");return s.getIn(this.data,u.check(t,"string|number")?[t]:t)},r.prototype.get=function(){var t=this.reference.apply(this,arguments);return this.options.clone?this._cloner(t):t},r.prototype.clone=function(){return this._cloner(this.reference.apply(this,arguments))},r.prototype.set=function(t,e){if(arguments.length<2)throw Error("Baobab.set: expects a key and a value.");var r={};return r[t]={$set:e},this.update(r)},r.prototype.update=function(t){return this._stack(t)},r.prototype.hasHistory=function(){return!!this._history.length},r.prototype.getHistory=function(){return this._history},r.prototype.undo=function(){if(!this.hasHistory())throw Error("Baobab.undo: no history recorded, cannot undo.");var t=this._history.shift();this.commit(t)},u.add("baobab",function(t){return t instanceof r}),r.prototype.toJSON=function(){return this.reference()},e.exports=r},{"../defaults.json":1,"./cursor.js":8,"./helpers.js":9,"./merge.js":10,"./mixins.js":11,"./typology.js":12,"./update.js":13,emmett:4,typology:5}],7:[function(t,e){function r(t,e){e.on("update",t.cursorListener)}function n(t){var e=this;if(arguments.length<2)throw Error("baobab.Combination: not enough arguments.");var n=arguments[1],a=s.arrayOf(arguments).slice(2);if(n instanceof Array&&(a=n.slice(1),n=n[0]),!i.check(n,"cursor"))throw Error("baobab.Combination: argument should be a cursor.");if("or"!==t&&"and"!==t)throw Error("baobab.Combination: invalid operator.");o.call(this),this.cursors=[n],this.operators=[],this.root=n.root,this.updates=new Array(this.cursors.length),this.cursorListener=function(){e.updates[e.cursors.indexOf(this)]=!0},this.treeListener=function(){var t,r,n=e.updates[0];for(t=1,r=e.cursors.length;r>t;t++)n="or"===e.operators[t-1]?n||e.updates[t]:n&&e.updates[t];n&&e.emit("update"),e.updates=new Array(e.cursors.length)},this.root.on("update",this.treeListener),r(this,n),a.forEach(function(e){this[t](e)},this)}var o=t("emmett"),i=t("./typology.js"),s=t("./helpers.js");s.inherits(n,o),n.prototype.or=function(t){if(!i.check(t,"cursor"))throw Error("baobab.Combination.or: argument should be a cursor.");if(~this.cursors.indexOf(t))throw Error("baobab.Combination.or: cursor already in combination.");return this.cursors.push(t),this.operators.push("or"),this.updates.length++,r(this,t),this},n.prototype.and=function(t){if(!i.check(t,"cursor"))throw Error("baobab.Combination.and: argument should be a cursor.");if(~this.cursors.indexOf(t))throw Error("baobab.Combination.and: cursor already in combination.");return this.cursors.push(t),this.operators.push("and"),this.updates.length++,r(this,t),this},n.prototype.release=function(){this.unbindAll(),this.cursors.forEach(function(t){t.off("update",this.cursorListener)},this),this.root.off("update",this.treeListener),this.cursors=null,this.operators=null,this.root=null,this.updates=null},e.exports=n},{"./helpers.js":9,"./typology.js":12,emmett:4}],8:[function(t,e){function r(t,e,r){var o=this;n.call(this),e=e||[],this.root=t,this.path=e,this.relevant=void 0!==this.reference(),this.complexPath=!!r,this.solvedPath=this.complexPath?r:this.path,this.updateHandler=function(t){var e,r,n,i,a,h,u=t.data.log,c=!1;if(o.complexPath&&(o.solvedPath=s.solvePath(o.root.data,o.path)),this._handlers.update.length||this._handlersAll.length){if(!o.path.length)return o.emit("update");t:for(a=0,n=u.length;n>a;a++)for(e=u[a],h=0,i=e.length;i>h&&(r=e[h],r===o.solvedPath[h]);h++)if(h+1===i||h+1===o.solvedPath.length){c=!0;break t}var l=void 0!==o.reference();o.relevant?l&&c?o.emit("update"):(o.emit("irrelevant"),o.relevant=!1):l&&c&&(o.emit("relevant"),o.emit("update"),o.relevant=!0)}},this.root.on("update",this.updateHandler),this.mixin=i.cursor(this)}var n=t("emmett"),o=t("./combination.js"),i=t("./mixins.js"),s=t("./helpers.js"),a=t("./typology.js");s.inherits(r,n),r.prototype._stack=function(t){return this.root._stack(s.pathObject(this.solvedPath,t)),this},r.prototype.isRoot=function(){return!this.path.length},r.prototype.isLeaf=function(){return a.check(this.reference(),"primitive")},r.prototype.isBranch=function(){return!this.isLeaf()&&!this.isRoot()},r.prototype.select=function(t){if(arguments.length>1&&(t=s.arrayOf(arguments)),!a.check(t,"path"))throw Error("baobab.Cursor.select: invalid path.");return this.root.select(this.path.concat(t))},r.prototype.up=function(){return this.solvedPath&&this.solvedPath.length?this.root.select(this.path.slice(0,-1)):null},r.prototype.left=function(){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.root.select(this.solvedPath.slice(0,-1).concat(t-1)):null},r.prototype.leftmost=function(){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.root.select(this.solvedPath.slice(0,-1).concat(0))},r.prototype.right=function(){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().reference().length?null:this.root.select(this.solvedPath.slice(0,-1).concat(t+1))},r.prototype.rightmost=function(){var t=+this.solvedPath[this.solvedPath.length-1];if(isNaN(t))throw Error("baobab.Cursor.right: cannot go right on a non-list type.");var e=this.up().reference();return this.root.select(this.solvedPath.slice(0,-1).concat(e.length-1))},r.prototype.down=function(){+this.solvedPath[this.solvedPath.length-1];return this.reference()instanceof Array?this.root.select(this.solvedPath.concat(0)):null},r.prototype.get=function(t){return arguments.length>1&&(t=s.arrayOf(arguments)),this.root.get(a.check(t,"step")?this.solvedPath.concat(t):this.solvedPath)},r.prototype.reference=function(t){return arguments.length>1&&(t=s.arrayOf(arguments)),this.root.reference(a.check(t,"step")?this.solvedPath.concat(t):this.solvedPath)},r.prototype.clone=function(t){return arguments.length>1&&(t=s.arrayOf(arguments)),this.root.clone(a.check(t,"step")?this.solvedPath.concat(t):this.solvedPath)},r.prototype.set=function(t,e){if(arguments.length<2)throw Error("baobab.Cursor.set: expecting at least key/value.");var r={};return r[t]={$set:e},this.update(r)},r.prototype.edit=function(t){return this.update({$set:t})},r.prototype.apply=function(t){if("function"!=typeof t)throw Error("baobab.Cursor.apply: argument is not a function.");return this.update({$apply:t})},r.prototype.thread=function(t){if("function"!=typeof t)throw Error("baobab.Cursor.thread: argument is not a function.");return this.update({$thread:t})},r.prototype.push=function(t){if(!(this.reference()instanceof Array))throw Error("baobab.Cursor.push: trying to push to non-array value.");return this.update(arguments.length>1?{$push:s.arrayOf(arguments)}:{$push:t})},r.prototype.unshift=function(t){if(!(this.reference()instanceof Array))throw Error("baobab.Cursor.push: trying to push to non-array value.");return this.update(arguments.length>1?{$unshift:s.arrayOf(arguments)}:{$unshift:t})},r.prototype.merge=function(t){if(!a.check(t,"object"))throw Error("baobab.Cursor.merge: trying to merge a non-object.");if(!a.check(this.reference(),"object"))throw Error("baobab.Cursor.merge: trying to merge into a non-object.");this.update({$merge:t})},r.prototype.update=function(t){return this._stack(t)},r.prototype.or=function(t){return new o("or",this,t)},r.prototype.and=function(t){return new o("and",this,t)},r.prototype.release=function(){this.root.off("update",this.updateHandler),this.root=null,this.unbindAll()},r.prototype.toJSON=function(){return this.reference()},a.add("cursor",function(t){return t instanceof r}),e.exports=r},{"./combination.js":7,"./helpers.js":9,"./mixins.js":11,"./typology.js":12,emmett:4}],9:[function(t,e){(function(r){function n(t){return Array.prototype.slice.call(t)}function o(t,e){var r,n={};for(r in t)n[r]=t[r];for(r in e)n[r]=e[r];return n}function i(t){if(!(t&&t instanceof Object))return t;if("array"===m.get(t))return t.slice(0);if("date"===m.get(t))return new Date(t.getTime());if("object"===m.get(t)){var e,r={};for(e in t)r[e]=t[e];return r}return t}function s(t){if(!(t&&t instanceof Object))return t;if("array"===m.get(t)){var e,r,n=[];for(e=0,r=t.length;r>e;e++)n.push(s(t[e]));return n}if("date"===m.get(t))return new Date(t.getTime());if("object"===m.get(t)){var o,i={};for(o in t)i[o]=s(t[o]);return i}return t}function a(t,e){return function(r){return e(t(r))}}function h(t,e){var r,n;for(r=0,n=t.length;n>r;r++)if(e(t[r]))return t[r]}function u(t,e){var r,n;for(r=0,n=t.length;n>r;r++)if(e(t[r]))return r;return-1}function c(t,e){var r,n=!0;for(r in e)if("object"===m.get(e[r]))n=n&&c(t[r]);else if("array"===m.get(e[r]))n=n&&!!~e[r].indexOf(t[r]);else if(t[r]!==e[r])return!1;return n}function l(t,e){return h(t,function(t){return c(t,e)})}function f(t,e){return indexOf(t,function(t){return c(t,e)})}function p(t,e){e=e||[];var r,n,o=t;for(r=0,n=e.length;n>r;r++){if(!o)return;if("function"==typeof e[r]){if("array"!==m.get(o))return;o=h(o,e[r])}else if("object"==typeof e[r]){if("array"!==m.get(o))return;o=l(o,e[r])}else o=o[e[r]]}return o}function d(t,e){var r,n,o,i=[],s=t;for(n=0,o=e.length;o>n;n++){if(!s)return null;if("function"==typeof e[n]){if("array"!==m.get(s))return;r=u(s,e[n]),i.push(r),s=s[r]}else if("object"==typeof e[n]){if("array"!==m.get(s))return;r=u(f(s,e[n])),i.push(r),s=s[r]}else i.push(e[n]),s=s[e[n]]}return i}function y(t,e){var r,n=t.length,o={},i=o;for(n||(o=e),r=0;n>r;r++)i[t[r]]=r+1===n?e:{},i=i[t[r]];return o}function g(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}var m=t("typology"),b="undefined"==typeof window?r.nextTick:"requestAnimationFrame"in window?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,0)};e.exports={arrayOf:n,deepClone:s,shallowClone:i,shallowMerge:o,compose:a,getIn:p,inherits:g,later:b,pathObject:y,solvePath:d}}).call(this,t("_process"))},{_process:3,typology:5}],10:[function(t,e){function r(t,e){return e in(t||{})}function n(t,e,n){return r(t,n)&&r(e,n)}function o(){var t,e,r,a,h={},u=arguments.length;for(r=u-1;r>=0;r--)if(arguments[r].$set)delete h.$apply,delete h.$merge,h.$set=arguments[r].$set;else if(arguments[r].$merge)delete h.$set,delete h.$apply,h.$merge=arguments[r].$merge;else if(arguments[r].$apply)delete h.$set,delete h.$merge,h.$apply=arguments[r].$apply;else if(arguments[r].$chain)delete h.$set,delete h.$merge,h.$apply=h.$apply?s.compose(h.$apply,arguments[r].$chain):arguments[r].$chain;else for(a in arguments[r])t=h[a],e=arguments[r][a],t&&i.check(e,"object")?n(t,e,"$push")?t.$push=i.check(t.$push,"array")?t.$push.concat(e.$push):[t.$push].concat(e.$push):n(t,e,"$unshift")?t.$unshift=i.check(e.$unshift,"array")?e.$unshift.concat(t.$unshift):[e.$unshift].concat(t.$unshift):h[a]=o(e,t):h[a]=e;return h}var i=t("typology"),s=t("./helpers.js");e.exports=o},{"./helpers.js":9,typology:5}],11:[function(t,e){var r=t("./typology.js"),n=t("./combination.js");e.exports={baobab:function(t){return{mixins:[{getInitialState:function(){if(this.tree=t,this.__type=null,this.cursor&&this.cursors)throw Error("baobab.mixin: you cannot have both `component.cursor` and `component.cursors`. Please make up your mind.");if(this.__updateHandler=function(){this.setState(this.__getCursorData())}.bind(this),this.cursor){if(!r.check(this.cursor,"string|number|array|cursor"))throw Error("baobab.mixin.cursor: invalid data (cursor, string or array).");r.check(this.cursor,"cursor")||(this.cursor=t.select(this.cursor)),this.__getCursorData=function(){return{cursor:this.cursor.get()}}.bind(this),this.__type="single"}else if(this.cursors){if(!r.check(this.cursors,"object|array"))throw Error("baobab.mixin.cursor: invalid data (object or array).");if(r.check(this.cursors,"array"))this.cursors=this.cursors.map(function(e){return r.check(e,"cursor")?e:t.select(e)}),this.__getCursorData=function(){return{cursors:this.cursors.map(function(t){return t.get()})}}.bind(this),this.__type="array";else{for(var e in this.cursors)r.check(this.cursors[e],"cursor")||(this.cursors[e]=t.select(this.cursors[e]));this.__getCursorData=function(){var t={};for(e in this.cursors)t[e]=this.cursors[e].get();return{cursors:t}}.bind(this),this.__type="object"}}return this.__getCursorData()},componentDidMount:function(){"single"===this.__type?this.cursor.on("update",this.__updateHandler):"array"===this.__type?(this.__combination=new n("or",this.cursors),this.__combination.on("update",this.__updateHandler)):"object"===this.__type&&(this.__combination=new n("or",Object.keys(this.cursors).map(function(t){return this.cursors[t]},this)),this.__combination.on("update",this.__updateHandler))},componentWillUnmount:function(){"single"===this.__type?this.cursor.off("update",this.__updateHandler):this.__combination.release()}}].concat(t.options.mixins)}},cursor:function(t){return{mixins:[{getInitialState:function(){return this.cursor=t,this.__updateHandler=function(){this.setState({cursor:this.cursor.get()})}.bind(this),{cursor:this.cursor.get()}},componentDidMount:function(){this.cursor.on("update",this.__updateHandler)},componentWillUnmount:function(){this.cursor.off("update",this.__updateHandler)}}].concat(t.root.options.mixins)}}}},{"./combination.js":7,"./typology.js":12}],12:[function(t,e){var r=t("typology"),n=new r({complexStep:"function|object",step:"string|number|array|function|object",path:function(t){return this.check(t,"?string|number|function|object")||this.check(t,["string|number|function|object"])},typology:function(t){return t instanceof r}});e.exports=n},{typology:5}],13:[function(t,e){function r(t,e){var r=new Error("precursors.update: "+e+" at path /"+t.toString());return r.path=t,r}function n(t,e,n){n=n||{};var a={};return function h(t,e,u){u=u||[];var c,l,f,p,d=u.join("λ");for(f in e)if(s[f])switch(p=e[f],a[d]=!0,f){case"$push":if(!o.check(t,"array"))throw r(u,"using command $push to a non array");o.check(p,"array")?t.push.apply(t,p):t.push(p);break;case"$unshift":if(!o.check(t,"array"))throw r(u,"using command $unshift to a non array");o.check(p,"array")?t.unshift.apply(t,p):t.unshift(p)}else if(l=d?d+"λ"+f:f,"$set"in(e[f]||{}))p=e[f].$set,a[l]=!0,t[f]=p;else if("$apply"in(e[f]||{})){if(c=e[f].$apply,"function"!=typeof c)throw r(u.concat(f),"using command $apply with a non function");a[l]=!0,t[f]=c.call(null,t[f])}else if("$merge"in(e[f]||{})){if(p=e[f].$merge,!o.check(t[f],"object"))throw r(u.concat(f),"using command $merge on a non-object");a[l]=!0,t[f]=i.shallowMerge(t[f],p)}else if(n.shiftReferences&&("$push"in(e[f]||{})||"$unshift"in(e[f]||{}))){if("$push"in(e[f]||{})){if(p=e[f].$push,!o.check(t[f],"array"))throw r(u.concat(f),"using command $push to a non array");t[f]=t[f].concat(p)}if("$unshift"in(e[f]||{})){if(p=e[f].$unshift,!o.check(t[f],"array"))throw r(u.concat(f),"using command $unshift to a non array");t[f]=(p instanceof Array?p:[p]).concat(t[f])}a[l]=!0}else"undefined"==typeof t[f]&&(t[f]={}),n.shiftReferences&&(t[f]=i.shallowClone(t[f])),h(t[f],e[f],u.concat(f))}(t,e),Object.keys(a).map(function(t){return t.split("λ")})}var o=t("./typology.js"),i=t("./helpers.js"),s={};["$set","$push","$unshift","$apply","$merge"].forEach(function(t){s[t]=!0}),e.exports=n},{"./helpers.js":9,"./typology.js":12}]},{},[2])(2)}); \ No newline at end of file diff --git a/index.js b/index.js index d4b37b7..8a98d74 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ var Baobab = require('./src/baobab.js'), // Non-writable version Object.defineProperty(Baobab, 'version', { - value: '0.3.0' + value: '0.3.1' }); // Exposing helpers diff --git a/package.json b/package.json index b1d26af..2f556fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "baobab", - "version": "0.3.0", + "version": "0.3.1", "description": "JavaScript data tree with cursors.", "main": "index.js", "dependencies": {