From aa7890f967c9c319094a7eeaf8f34c3ae744c20b Mon Sep 17 00:00:00 2001 From: Yomguithereal Date: Sat, 13 Dec 2014 14:47:01 +0100 Subject: [PATCH] Bump 0.1.0 --- build/baobab.min.js | 2 +- index.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/baobab.min.js b/build/baobab.min.js index d003970..c4c3993 100644 --- a/build/baobab.min.js +++ b/build/baobab.min.js @@ -1 +1 @@ -!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 i(s,a){if(!r[s]){if(!t[s]){var h="function"==typeof require&&require;if(!a&&h)return h(s,!0);if(o)return o(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 i(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var o="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"},i=function(){this._enabled=!0,this._children=[],this._handlers={},this._handlersAll=[]};i.prototype.on=function(t,r,n){var o,s,a,h,u,c;if("function"==typeof r){for(u="string"==typeof t?[t]:t,o=0,s=u.length;o!==s;o+=1)if(h=u[o]){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)i.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},i.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},i.prototype.off=function(t,e){var r,n,i,o,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=[],i=0,o=this._handlers[h].length;i!==o;i+=1)this._handlers[h][i].handler!==e&&a.push(this._handlers[h][i]);this._handlers[h]=a}this._handlers[h]&&0===this._handlers[h].length&&delete this._handlers[h]}return this},i.prototype.unbindAll=function(){var t;this._handlersAll=[];for(t in this._handlers)delete this._handlers[t];return this},i.prototype.emit=function(t,e){var r,n,i,o,s,a,h,u,c,p="string"==typeof t?[t]:t;if(!this._enabled)return this;for(e=void 0===e?{}:e,r=0,n=p.length;r!==n;r+=1)if(c=p[r],u=(this._handlers[c]||[]).concat(this._handlersAll),u.length){for(a={type:c,data:e||{},target:this},s=[],i=0,o=u.length;i!==o;i+=1)u[i].handler.call("scope"in u[i]?u[i].scope:this,a),u[i].once||s.push(u[i]);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},i.prototype.child=function(){var t=this,e=new i;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},i.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},i.prototype.disable=function(){return this._enabled=!1,this},i.prototype.enable=function(){return this._enabled=!0,this},i.version="2.1.1","undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=i),n.Emitter=i):"function"==typeof t&&t.amd?t("emmett",[],function(){return i}):this.Emitter=i}).call(this)},{}],5:[function(e,r,n){!function(){"use strict";function e(t){t=t||{};var e={};if(this.add=function(t,r){var n,i,o,s,a,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.");n=t,s=n.id,u=n.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.");s=t,u=r}if("string"!==this.get(s)||0===s.length)throw new Error("A type requires an string id.");if(void 0!==e[s]&&"proto"!==e[s])throw new Error('The type "'+s+'" already exists.');if(~h.indexOf(s))throw new Error('"'+s+'" is a reserved type name.');e[s]=1,o=(n||{}).proto||[],o=Array.isArray(o)?o:[o],a={};for(i in o)void 0===e[o[i]]&&(e[o[i]]=1,a[o[i]]=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(e[s]=void 0===n?{id:s,type:u}:{},void 0!==n)for(i in n)e[s][i]=n[i];for(i in a)i!==s&&delete e[i];return this},this.has=function(t){return!!e[t]},this.get=function(t){return null===t||void 0===t?String(t):a[Object.prototype.toString.call(t)]||"object"},this.check=function(t,r){var n,i,o,s=!1,a=!1,u=this.get(t);if("string"===this.get(r)){n=r.replace(/^[?!]/,"").split(/\|/);for(i in n)if(h.indexOf(n[i])<0&&!(n[i]in e))throw new Error("Invalid type.");r.match(/^\?/)&&(s=!0,r=r.replace(/^\?/,"")),r.match(/^!/)&&(a=!0,r=r.replace(/^!/,""));for(i in n)if(e[n[i]]&&("function"==typeof e[n[i]].type?e[n[i]].type.call(this,t)===!0:this.check(t,e[n[i]].type)))return!a;return null===t||void 0===t?a?!s:s:a?!(~n.indexOf("*")||~n.indexOf(u)):!(!~n.indexOf("*")&&!~n.indexOf(u))}if("object"===this.get(r)){if("object"!==u)return!1;for(o in r)if(!this.check(t[o],r[o]))return!1;for(o in t)if(void 0===r[o])return!1;return!0}if("array"===this.get(r)){if("array"!==u)return!1;if(1!==r.length)throw new Error("Invalid type.");for(o in t)if(!this.check(t[o],r[0]))return!1;return!0}return!1},this.isValid=function(t){var r,n,i;if("string"===this.get(t)){r=t.replace(/^[?!]/,"").split(/\|/);for(i in r)if(h.indexOf(r[i])<0&&!(r[i]in e))return!1;return!0}if("object"===this.get(t)){for(n in t)if(!this.isValid(t[n]))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)}),"object"!==this.get(t))throw Error("Invalid argument.");for(var r in t)this.add(r,t[r])}var i,o,s=["Arguments","Boolean","Number","String","Function","Array","Date","RegExp","Object"],a={},h=["*"];for(i in s)o=s[i],h.push(o.toLowerCase()),a["[object "+o+"]"]=o.toLowerCase();var u=e;e.call(u),Object.defineProperty(u,"version",{value:"0.2.1"}),"undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=u),n.types=u):"function"==typeof t&&t.amd?t("typology",[],function(){return u}):this.types=u}(this)},{}],6:[function(t,e){function r(t,e){if(!(this instanceof r))return new r(t,e);if(!u.check(t,"object"))throw Error("Baobab: invalid data.");if(i.call(this),this.options=h(e,p),this._cloner=this.options.cloningFunction||s.clone,this.data=this._cloner(t),this._futureUpdate={},this._willUpdate=!1,this._history=[],this._registeredCursors={},this.typology=this.options.typology?u.check(this.options.typology,"typology")?this.options.typology:new o(this.options.typology):new o,this.validate=this.options.validate||null,!this.check())throw Error("Baobab: instantiating with invalid data");this.mixin=c.baobab(this)}var n=t("./cursor.js"),i=t("emmett"),o=t("typology"),s=t("./helpers.js"),a=t("./update.js"),h=t("./merge.js"),u=t("./typology.js"),c=t("./mixins.js"),p=t("../defaults.json");s.inherits(r,i),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.delay?(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.check=function(){return this.validate?this.typology.check(this.data,this.validate):!0},r.prototype.commit=function(t){var e;if(t)this.data=t.data,e=t.log;else{var r=this._archive();e=a(this.data,this._futureUpdate),r&&(r.log=e)}return this.check()||this.emit("invalid"),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.");if(t="string"==typeof t?[t]:t,this.options.cursorSingletons){var e=t.join("λ");if(this._registeredCursors[e])return this._registeredCursors[e];var r=new n(this,t);return this._registeredCursors[e]=r,r}return new n(this,t)},r.prototype.get=function(t){var e;return arguments.length>1&&(t=s.arrayOf(arguments)),e=t?s.getIn(this.data,"string"==typeof t?[t]:t):this.data,this.options.clone?this._cloner(e):e},r.prototype.reference=function(t){var e;return arguments.length>1&&(t=s.arrayOf(arguments)),e=t?s.getIn(this.data,"string"==typeof t?[t]:t):this.data},r.prototype.clone=function(t){var e;return arguments.length>1&&(t=s.arrayOf(arguments)),e=t?s.getIn(this.data,"string"==typeof t?[t]:t):this.data,this._cloner(e)},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.get()},e.exports=r},{"../defaults.json":1,"./cursor.js":7,"./helpers.js":8,"./merge.js":9,"./mixins.js":10,"./typology.js":11,"./update.js":12,emmett:4,typology:5}],7:[function(t,e){function r(t,e){var r=this;n.call(this),e=e||[],this.root=t,this.path=e,this.relevant=void 0!==this.reference(),this.root.on("update",function(t){var e,n,i,o,s,a,h=t.data.log,u=!1;if(!r.path.length)return r.emit("update");t:for(s=0,i=h.length;i>s;s++)for(e=h[s],a=0,o=e.length;o>a&&(n=e[a],n===r.path[a]);a++)if(a+1===o||a+1===r.path.length){u=!0;break t}var c=void 0!==r.reference();r.relevant?c&&u?r.emit("update"):(r.emit("irrelevant"),r.relevant=!1):c&&u&&(r.emit("relevant"),r.emit("update"),r.relevant=!0)}),this.mixin=i.cursor(this)}var n=t("emmett"),i=t("./mixins.js"),o=t("./helpers.js"),s=t("./typology.js");o.inherits(r,n),r.prototype._stack=function(t){return this.root._stack(o.pathObject(this.path,t)),this},r.prototype.select=function(t){if(arguments.length>1&&(t=o.arrayOf(arguments)),!s.check(t,"path"))throw Error("baobab.Cursor.select: invalid path.");return this.root.select(this.path.concat(t))},r.prototype.up=function(){return this.root.select(this.path.length?this.path.slice(0,-1):[])},r.prototype.left=function(){var t=+this.path[this.path.length-1];if(isNaN(t))throw Error("baobab.Cursor.left: cannot go left on a non-list type.");return this.root.select(this.path.slice(0,-1).concat(t-1))},r.prototype.right=function(){var t=+this.path[this.path.length-1];if(isNaN(t))throw Error("baobab.Cursor.right: cannot go right on a non-list type.");return this.root.select(this.path.slice(0,-1).concat(t+1))},r.prototype.down=function(){+this.path[this.path.length-1];if(!(this.reference()instanceof Array))throw Error("baobab.Cursor.down: cannot descend on a non-list type.");return this.root.select(this.path.concat(0))},r.prototype.get=function(t){return arguments.length>1&&(t=o.arrayOf(arguments)),this.root.get(t?this.path.concat(t):this.path)},r.prototype.reference=function(t){return arguments.length>1&&(t=o.arrayOf(arguments)),this.root.reference(t?this.path.concat(t):this.path)},r.prototype.clone=function(t){return arguments.length>1&&(t=o.arrayOf(arguments)),this.root.clone(t?this.path.concat(t):this.path)},r.prototype.set=function(t,e){if(arguments.length<2)return this.update({$set:t});var r={};return r[t]={$set:e},this.update(r)},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){return this.update(arguments.length>1?{$push:o.arrayOf(arguments)}:{$push:t})},r.prototype.unshift=function(t){return this.update(arguments.length>1?{$unshift:o.arrayOf(arguments)}:{$unshift:t})},r.prototype.update=function(t){return this._stack(t)},s.add("cursor",function(t){return t instanceof r}),r.prototype.toJSON=function(){return this.get()},e.exports=r},{"./helpers.js":8,"./mixins.js":10,"./typology.js":11,emmett:4}],8:[function(t,e){(function(r){function n(t){return Array.prototype.slice.call(t)}function i(t){if(!t)return t;var e,r,n;if(u.check(t,"array"))for(e=[],r=0,n=t.length;n>r;r++)e.push(i(t[r]));else if(u.check(t,"date"))e=new Date(t.getTime());else if(u.check(t,"object"))if(t.nodeType&&"function"==typeof t.cloneNode)e=t;else if(t.prototype)e=t;else{e={};for(r in t)e[r]=i(t[r])}else e=t;return e}function o(t,e){return function(r){return e(t(r))}}function s(t,e){e=e||[];var r,n,i=t;for(r=0,n=e.length;n>r;r++){if("undefined"==typeof i[e[r]])return;i=i[e[r]]}return i}function a(t,e){var r,n=t.length,i={},o=i;for(n||(i=e),r=0;n>r;r++)o[t[r]]=r+1===n?e:{},o=o[t[r]];return i}function h(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}var u=t("typology"),c="undefined"==typeof window?r.nextTick:"requestAnimationFrame"in window?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,0)};e.exports={arrayOf:n,clone:i,compose:o,getIn:s,inherits:h,later:c,pathObject:a}}).call(this,t("_process"))},{_process:3,typology:5}],9:[function(t,e){function r(t,e){return e in(t||{})}function n(t,e){for(var n=0,i=e.length;i>n;n++)if(r(t,e[n]))return!0;return!1}function i(t,e,n){return r(t,n)&&r(e,n)}function o(){var t,e,r,h,u={},c=arguments.length;for(r=c-1;r>=0;r--)if(n(arguments[r],["$set","$apply","$chain"]))u.$set&&(arguments[r].$apply||arguments[r].$chain)?(delete u.$set,u.$apply=arguments[r].$apply||arguments[r].$chain):u.$apply&&arguments[r].$set?(delete u.$apply,u.$set=arguments[r].$set):arguments[r].$set?u.$set=arguments[r].$set:arguments[r].$apply?u.$apply=arguments[r].$apply:arguments[r].$chain&&(u.$apply=u.$apply?a.compose(u.$apply,arguments[r].$chain):arguments[r].$chain);else for(h in arguments[r])t=u[h],e=arguments[r][h],t&&s.check(e,"object")?i(t,e,"$push")?t.$push=s.check(t.$push,"array")?t.$push.concat(e.$push):[t.$push].concat(e.$push):i(t,e,"$unshift")?t.$unshift=s.check(e.$unshift,"array")?e.$unshift.concat(t.$unshift):[e.$unshift].concat(t.$unshift):u[h]=o(e,t):u[h]=e;return u}var s=t("typology"),a=t("./helpers.js");e.exports=o},{"./helpers.js":8,typology:5}],10:[function(t,e){var r=t("./typology.js");e.exports={baobab:function(t){return{componentWillMount:function(){if(this.baobab=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.cursor){if(!r.check(this.cursor,"string|array|cursor"))throw Error("baobab.mixin.cursor: invalid data (cursor, string or array).");this.cursor=t.select(this.cursor),this.__type="single"}else if(this.cursors){if(!r.check(this.cursors,"object|array"))throw Error("baobab.mixin.cursor: invalid data (cursor, 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.__type="array";else{for(var e in this.cursors)r.check(path,"cursor")||(this.cursors[e]=t.select(this.cursors[e]));this.__type="object"}}var n=!1;this.__updateHandler=function(){n||(this.forceUpdate(),n=!0,setTimeout(function(){n=!1},0))}.bind(this)},componentDidMount:function(){if("single"===this.__type)this.cursor.on("update",this.__updateHandler);else if("array"===this.__type)this.cursors.forEach(function(t){t.on("update",this.__updateHandler)},this);else if("object"===this.__type)for(var t in this.cursors)cursors[t].on("update",this.__updateHandler)},componentWillUnmount:function(){if("single"===this.__type)this.cursor.off("update",this.__updateHandler);else if("array"===this.__type)this.cursors.forEach(function(t){t.off("update",this.__updateHandler)},this);else if("object"===this.__type)for(var t in this.cursors)cursors[t].off("update",this.__updateHandler)}}},cursor:function(t){return{componentWillMount:function(){this.cursor=t,this.__updateHandler=function(){this.forceUpdate()}.bind(this)},componentDidMount:function(){this.cursor.on("update",this.__updateHandler)},componentWillUnmount:function(){this.cursor.off("update",this.__updateHandler)}}}}},{"./typology.js":11}],11:[function(t,e){var r=t("typology"),n=new r({path:function(t){return this.check(t,"?string|number")||this.check(t,["string|number"])},typology:function(t){return t instanceof r}});e.exports=n},{typology:5}],12:[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,i,a){a=a||[];var h,u,c,p,f=a.join("λ");for(c in i)if(s[c])switch(p=i[c],f&&!t[f]&&(t[f]=!0),c){case"$push":if(!o.check(e,"array"))throw r(a,"using command $push to a non array");o.check(p,"array")?e.push.apply(e,p):e.push(p);break;case"$unshift":if(!o.check(e,"array"))throw r(a,"using command $unshift to a non array");o.check(p,"array")?e.unshift.apply(e,p):e.unshift(p)}else if("$set"in(i[c]||{}))u=f?f+"λ"+c:c,p=i[c].$set,u&&!t[u]&&(t[u]=!0),e[c]=p;else if("$apply"in(i[c]||{})){if(u=f?f+"λ"+c:c,h=i[c].$apply,"function"!=typeof h)throw r(a.concat(c),"using command $apply with a non function");u&&!t[u]&&(t[u]=!0),e[c]=h.call(null,e[c])}else"undefined"==typeof e[c]&&(e[c]={}),n(t,e[c],i[c],a.concat(c))}function i(t,e){var r={};return n(r,t,e),Object.keys(r).map(function(t){return t.split("λ")})}var o=t("./typology.js"),s={};["$set","$push","$unshift","$apply"].forEach(function(t){s[t]=!0}),e.exports=i},{"./typology.js":11}]},{},[2])(2)}); \ No newline at end of file +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{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 i(s,a){if(!r[s]){if(!t[s]){var h="function"==typeof require&&require;if(!a&&h)return h(s,!0);if(o)return o(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 i(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var o="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"},i=function(){this._enabled=!0,this._children=[],this._handlers={},this._handlersAll=[]};i.prototype.on=function(t,r,n){var o,s,a,h,u,c;if("function"==typeof r){for(u="string"==typeof t?[t]:t,o=0,s=u.length;o!==s;o+=1)if(h=u[o]){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)i.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},i.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},i.prototype.off=function(t,e){var r,n,i,o,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=[],i=0,o=this._handlers[h].length;i!==o;i+=1)this._handlers[h][i].handler!==e&&a.push(this._handlers[h][i]);this._handlers[h]=a}this._handlers[h]&&0===this._handlers[h].length&&delete this._handlers[h]}return this},i.prototype.unbindAll=function(){var t;this._handlersAll=[];for(t in this._handlers)delete this._handlers[t];return this},i.prototype.emit=function(t,e){var r,n,i,o,s,a,h,u,c,p="string"==typeof t?[t]:t;if(!this._enabled)return this;for(e=void 0===e?{}:e,r=0,n=p.length;r!==n;r+=1)if(c=p[r],u=(this._handlers[c]||[]).concat(this._handlersAll),u.length){for(a={type:c,data:e||{},target:this},s=[],i=0,o=u.length;i!==o;i+=1)u[i].handler.call("scope"in u[i]?u[i].scope:this,a),u[i].once||s.push(u[i]);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},i.prototype.child=function(){var t=this,e=new i;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},i.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},i.prototype.disable=function(){return this._enabled=!1,this},i.prototype.enable=function(){return this._enabled=!0,this},i.version="2.1.1","undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=i),n.Emitter=i):"function"==typeof t&&t.amd?t("emmett",[],function(){return i}):this.Emitter=i}).call(this)},{}],5:[function(e,r,n){!function(){"use strict";function e(t){t=t||{};var e={};if(this.add=function(t,r){var n,i,o,s,a,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.");n=t,s=n.id,u=n.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.");s=t,u=r}if("string"!==this.get(s)||0===s.length)throw new Error("A type requires an string id.");if(void 0!==e[s]&&"proto"!==e[s])throw new Error('The type "'+s+'" already exists.');if(~h.indexOf(s))throw new Error('"'+s+'" is a reserved type name.');e[s]=1,o=(n||{}).proto||[],o=Array.isArray(o)?o:[o],a={};for(i in o)void 0===e[o[i]]&&(e[o[i]]=1,a[o[i]]=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(e[s]=void 0===n?{id:s,type:u}:{},void 0!==n)for(i in n)e[s][i]=n[i];for(i in a)i!==s&&delete e[i];return this},this.has=function(t){return!!e[t]},this.get=function(t){return null===t||void 0===t?String(t):a[Object.prototype.toString.call(t)]||"object"},this.check=function(t,r){var n,i,o,s=!1,a=!1,u=this.get(t);if("string"===this.get(r)){n=r.replace(/^[?!]/,"").split(/\|/);for(i in n)if(h.indexOf(n[i])<0&&!(n[i]in e))throw new Error("Invalid type.");r.match(/^\?/)&&(s=!0,r=r.replace(/^\?/,"")),r.match(/^!/)&&(a=!0,r=r.replace(/^!/,""));for(i in n)if(e[n[i]]&&("function"==typeof e[n[i]].type?e[n[i]].type.call(this,t)===!0:this.check(t,e[n[i]].type)))return!a;return null===t||void 0===t?a?!s:s:a?!(~n.indexOf("*")||~n.indexOf(u)):!(!~n.indexOf("*")&&!~n.indexOf(u))}if("object"===this.get(r)){if("object"!==u)return!1;for(o in r)if(!this.check(t[o],r[o]))return!1;for(o in t)if(void 0===r[o])return!1;return!0}if("array"===this.get(r)){if("array"!==u)return!1;if(1!==r.length)throw new Error("Invalid type.");for(o in t)if(!this.check(t[o],r[0]))return!1;return!0}return!1},this.isValid=function(t){var r,n,i;if("string"===this.get(t)){r=t.replace(/^[?!]/,"").split(/\|/);for(i in r)if(h.indexOf(r[i])<0&&!(r[i]in e))return!1;return!0}if("object"===this.get(t)){for(n in t)if(!this.isValid(t[n]))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)}),"object"!==this.get(t))throw Error("Invalid argument.");for(var r in t)this.add(r,t[r])}var i,o,s=["Arguments","Boolean","Number","String","Function","Array","Date","RegExp","Object"],a={},h=["*"];for(i in s)o=s[i],h.push(o.toLowerCase()),a["[object "+o+"]"]=o.toLowerCase();var u=e;e.call(u),Object.defineProperty(u,"version",{value:"0.2.1"}),"undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=u),n.types=u):"function"==typeof t&&t.amd?t("typology",[],function(){return u}):this.types=u}(this)},{}],6:[function(t,e){function r(t,e){if(!(this instanceof r))return new r(t,e);if(!u.check(t,"object"))throw Error("Baobab: invalid data.");if(i.call(this),this.options=h(e,p),this._cloner=this.options.cloningFunction||s.clone,this.data=this._cloner(t),this._futureUpdate={},this._willUpdate=!1,this._history=[],this._registeredCursors={},this.typology=this.options.typology?u.check(this.options.typology,"typology")?this.options.typology:new o(this.options.typology):new o,this.validate=this.options.validate||null,!this.check())throw Error("Baobab: instantiating with invalid data");this.mixin=c.baobab(this)}var n=t("./cursor.js"),i=t("emmett"),o=t("typology"),s=t("./helpers.js"),a=t("./update.js"),h=t("./merge.js"),u=t("./typology.js"),c=t("./mixins.js"),p=t("../defaults.json");s.inherits(r,i),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.delay?(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.check=function(){return this.validate?this.typology.check(this.data,this.validate):!0},r.prototype.commit=function(t){var e;if(t)this.data=t.data,e=t.log;else{var r=this._archive();e=a(this.data,this._futureUpdate),r&&(r.log=e)}return this.check()||this.emit("invalid"),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.");if(t="string"==typeof t?[t]:t,this.options.cursorSingletons){var e=t.join("λ");if(this._registeredCursors[e])return this._registeredCursors[e];var r=new n(this,t);return this._registeredCursors[e]=r,r}return new n(this,t)},r.prototype.get=function(t){var e;return arguments.length>1&&(t=s.arrayOf(arguments)),e=t?s.getIn(this.data,"string"==typeof t?[t]:t):this.data,this.options.clone?this._cloner(e):e},r.prototype.reference=function(t){var e;return arguments.length>1&&(t=s.arrayOf(arguments)),e=t?s.getIn(this.data,"string"==typeof t?[t]:t):this.data},r.prototype.clone=function(t){var e;return arguments.length>1&&(t=s.arrayOf(arguments)),e=t?s.getIn(this.data,"string"==typeof t?[t]:t):this.data,this._cloner(e)},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.get()},e.exports=r},{"../defaults.json":1,"./cursor.js":7,"./helpers.js":8,"./merge.js":9,"./mixins.js":10,"./typology.js":11,"./update.js":12,emmett:4,typology:5}],7:[function(t,e){function r(t,e){var r=this;n.call(this),e=e||[],this.root=t,this.path=e,this.relevant=void 0!==this.reference(),this.root.on("update",function(t){var e,n,i,o,s,a,h=t.data.log,u=!1;if(!r.path.length)return r.emit("update");t:for(s=0,i=h.length;i>s;s++)for(e=h[s],a=0,o=e.length;o>a&&(n=e[a],n===r.path[a]);a++)if(a+1===o||a+1===r.path.length){u=!0;break t}var c=void 0!==r.reference();r.relevant?c&&u?r.emit("update"):(r.emit("irrelevant"),r.relevant=!1):c&&u&&(r.emit("relevant"),r.emit("update"),r.relevant=!0)}),this.mixin=i.cursor(this)}var n=t("emmett"),i=t("./mixins.js"),o=t("./helpers.js"),s=t("./typology.js");o.inherits(r,n),r.prototype._stack=function(t){return this.root._stack(o.pathObject(this.path,t)),this},r.prototype.select=function(t){if(arguments.length>1&&(t=o.arrayOf(arguments)),!s.check(t,"path"))throw Error("baobab.Cursor.select: invalid path.");return this.root.select(this.path.concat(t))},r.prototype.up=function(){return this.root.select(this.path.length?this.path.slice(0,-1):[])},r.prototype.left=function(){var t=+this.path[this.path.length-1];if(isNaN(t))throw Error("baobab.Cursor.left: cannot go left on a non-list type.");return this.root.select(this.path.slice(0,-1).concat(t-1))},r.prototype.right=function(){var t=+this.path[this.path.length-1];if(isNaN(t))throw Error("baobab.Cursor.right: cannot go right on a non-list type.");return this.root.select(this.path.slice(0,-1).concat(t+1))},r.prototype.down=function(){+this.path[this.path.length-1];if(!(this.reference()instanceof Array))throw Error("baobab.Cursor.down: cannot descend on a non-list type.");return this.root.select(this.path.concat(0))},r.prototype.get=function(t){return arguments.length>1&&(t=o.arrayOf(arguments)),this.root.get(t?this.path.concat(t):this.path)},r.prototype.reference=function(t){return arguments.length>1&&(t=o.arrayOf(arguments)),this.root.reference(t?this.path.concat(t):this.path)},r.prototype.clone=function(t){return arguments.length>1&&(t=o.arrayOf(arguments)),this.root.clone(t?this.path.concat(t):this.path)},r.prototype.set=function(t,e){if(arguments.length<2)return this.update({$set:t});var r={};return r[t]={$set:e},this.update(r)},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){return this.update(arguments.length>1?{$push:o.arrayOf(arguments)}:{$push:t})},r.prototype.unshift=function(t){return this.update(arguments.length>1?{$unshift:o.arrayOf(arguments)}:{$unshift:t})},r.prototype.update=function(t){return this._stack(t)},s.add("cursor",function(t){return t instanceof r}),r.prototype.toJSON=function(){return this.get()},e.exports=r},{"./helpers.js":8,"./mixins.js":10,"./typology.js":11,emmett:4}],8:[function(t,e){(function(r){function n(t){return Array.prototype.slice.call(t)}function i(t){if(!t)return t;var e,r,n;if(u.check(t,"array"))for(e=[],r=0,n=t.length;n>r;r++)e.push(i(t[r]));else if(u.check(t,"date"))e=new Date(t.getTime());else if(u.check(t,"object"))if(t.nodeType&&"function"==typeof t.cloneNode)e=t;else if(t.prototype)e=t;else{e={};for(r in t)e[r]=i(t[r])}else e=t;return e}function o(t,e){return function(r){return e(t(r))}}function s(t,e){e=e||[];var r,n,i=t;for(r=0,n=e.length;n>r;r++){if("undefined"==typeof i[e[r]])return;i=i[e[r]]}return i}function a(t,e){var r,n=t.length,i={},o=i;for(n||(i=e),r=0;n>r;r++)o[t[r]]=r+1===n?e:{},o=o[t[r]];return i}function h(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}var u=t("typology"),c="undefined"==typeof window?r.nextTick:"requestAnimationFrame"in window?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,0)};e.exports={arrayOf:n,clone:i,compose:o,getIn:s,inherits:h,later:c,pathObject:a}}).call(this,t("_process"))},{_process:3,typology:5}],9:[function(t,e){function r(t,e){return e in(t||{})}function n(t,e){for(var n=0,i=e.length;i>n;n++)if(r(t,e[n]))return!0;return!1}function i(t,e,n){return r(t,n)&&r(e,n)}function o(){var t,e,r,h,u={},c=arguments.length;for(r=c-1;r>=0;r--)if(n(arguments[r],["$set","$apply","$chain"]))u.$set&&(arguments[r].$apply||arguments[r].$chain)?(delete u.$set,u.$apply=arguments[r].$apply||arguments[r].$chain):u.$apply&&arguments[r].$set?(delete u.$apply,u.$set=arguments[r].$set):arguments[r].$set?u.$set=arguments[r].$set:arguments[r].$apply?u.$apply=arguments[r].$apply:arguments[r].$chain&&(u.$apply=u.$apply?a.compose(u.$apply,arguments[r].$chain):arguments[r].$chain);else for(h in arguments[r])t=u[h],e=arguments[r][h],t&&s.check(e,"object")?i(t,e,"$push")?t.$push=s.check(t.$push,"array")?t.$push.concat(e.$push):[t.$push].concat(e.$push):i(t,e,"$unshift")?t.$unshift=s.check(e.$unshift,"array")?e.$unshift.concat(t.$unshift):[e.$unshift].concat(t.$unshift):u[h]=o(e,t):u[h]=e;return u}var s=t("typology"),a=t("./helpers.js");e.exports=o},{"./helpers.js":8,typology:5}],10:[function(t,e){var r=t("./typology.js");e.exports={baobab:function(t){return{componentWillMount:function(){if(this.baobab=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.cursor){if(!r.check(this.cursor,"string|array|cursor"))throw Error("baobab.mixin.cursor: invalid data (cursor, string or array).");this.cursor=t.select(this.cursor),this.__type="single"}else if(this.cursors){if(!r.check(this.cursors,"object|array"))throw Error("baobab.mixin.cursor: invalid data (cursor, 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.__type="array";else{for(var e in this.cursors)r.check(path,"cursor")||(this.cursors[e]=t.select(this.cursors[e]));this.__type="object"}}var n=!1;this.__updateHandler=function(){n||(this.forceUpdate(),n=!0,setTimeout(function(){n=!1},0))}.bind(this)},componentDidMount:function(){if("single"===this.__type)this.cursor.on("update",this.__updateHandler);else if("array"===this.__type)this.cursors.forEach(function(t){t.on("update",this.__updateHandler)},this);else if("object"===this.__type)for(var t in this.cursors)cursors[t].on("update",this.__updateHandler)},componentWillUnmount:function(){if("single"===this.__type)this.cursor.off("update",this.__updateHandler);else if("array"===this.__type)this.cursors.forEach(function(t){t.off("update",this.__updateHandler)},this);else if("object"===this.__type)for(var t in this.cursors)cursors[t].off("update",this.__updateHandler)}}},cursor:function(t){return{componentWillMount:function(){this.cursor=t,this.__updateHandler=function(){this.forceUpdate()}.bind(this)},componentDidMount:function(){this.cursor.on("update",this.__updateHandler)},componentWillUnmount:function(){this.cursor.off("update",this.__updateHandler)}}}}},{"./typology.js":11}],11:[function(t,e){var r=t("typology"),n=new r({path:function(t){return this.check(t,"?string|number")||this.check(t,["string|number"])},typology:function(t){return t instanceof r}});e.exports=n},{typology:5}],12:[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,i,a){a=a||[];var h,u,c,p,f=a.join("λ");for(c in i)if(s[c])switch(p=i[c],f&&!t[f]&&(t[f]=!0),c){case"$push":if(!o.check(e,"array"))throw r(a,"using command $push to a non array");o.check(p,"array")?e.push.apply(e,p):e.push(p);break;case"$unshift":if(!o.check(e,"array"))throw r(a,"using command $unshift to a non array");o.check(p,"array")?e.unshift.apply(e,p):e.unshift(p)}else if("$set"in(i[c]||{}))u=f?f+"λ"+c:c,p=i[c].$set,u&&!t[u]&&(t[u]=!0),e[c]=p;else if("$apply"in(i[c]||{})){if(u=f?f+"λ"+c:c,h=i[c].$apply,"function"!=typeof h)throw r(a.concat(c),"using command $apply with a non function");u&&!t[u]&&(t[u]=!0),e[c]=h.call(null,e[c])}else"undefined"==typeof e[c]&&(e[c]={}),n(t,e[c],i[c],a.concat(c))}function i(t,e){var r={};return n(r,t,e),Object.keys(r).map(function(t){return t.split("λ")})}var o=t("./typology.js"),s={};["$set","$push","$unshift","$apply"].forEach(function(t){s[t]=!0}),e.exports=i},{"./typology.js":11}]},{},[2])(2)}); \ No newline at end of file diff --git a/index.js b/index.js index 0261d2d..7320bab 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ var Baobab = require('./src/baobab.js'); // Non-writable version Object.defineProperty(Baobab, 'version', { - value: '0.0.1' + value: '0.1.0' }); // Exporting diff --git a/package.json b/package.json index 5c8f994..7d06880 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "baobab", - "version": "0.0.1", + "version": "0.1.0", "description": "JavaScript data tree with cursors.", "main": "index.js", "dependencies": {