Comparing version 0.4.2 to 0.5.0
# Changelog | ||
## 5.0.0 | ||
- Added `fetch`, which will return a pathway and allow a fallback if it doesn't exist | ||
## 0.4.2 | ||
@@ -4,0 +8,0 @@ |
@@ -1,2 +0,2 @@ | ||
module.exports=function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r,e){"use strict";function n(t,r){this._path=[],this._root=this,this._state=t}var i=e(4),u=e(5),o=e(2);n.prototype={getPath:function(t){return t?this._path.concat(t):this._path},getState:function(){return this._state},commit:function(t){this._root._state=t},get:function(t){return Object.create(this,{_path:{value:this.getPath(t)}})},set:function(t,r){1===arguments.length&&(r=arguments[0],t=void 0),this.commit(i(this.getState(),this.getPath(t),r))},remove:function(t){this.commit(u(this.getState(),this.getPath(t)))},keys:function(){return Object.keys(this.valueOf()||{})},values:function(){var t=this.valueOf();return this.keys().map(function(r){return t[r]})},valueOf:function(){return o(this.getState(),this.getPath())},toJSON:function(){return this.valueOf()},toArray:function(){return this.values()},find:function(){return this.filter.apply(this,arguments)[0]}};var s=["map","reduce","filter","forEach"];s.forEach(function(t){n.prototype[t]=function(){var r;return(r=this.toArray())[t].apply(r,arguments)}}),t.exports=n},function(t,r,e){"use strict";t.exports=function(t){if(Array.isArray(t))return t.slice();var r={};for(var e in t)r[e]=t[e];return r}},function(t,r,e){"use strict";var n=e(3);t.exports=function(t,r){for(var e=!0;e;){o=s=void 0,e=!1;var i=t,u=r,o=u[0],s=u.slice(1);if(!o)return i;if(n(i,u)===!1)return void 0;if(!s.length)return i[o];t=i[o],r=s,e=!0}}},function(t,r,e){"use strict";t.exports=function(t,r){var e=!0;t:for(;e;){u=o=s=a=void 0,e=!1;var n=t,i=r,u=i[0],o=i.slice(1),s=void 0!==n,a=s&&u in n;if(o.length){if(a){t=n[u],r=o,e=!0;continue t}return!1}return a}}},function(t,r,e){"use strict";var n=e(1),i=e(2);t.exports=function u(t,r,e){if(i(t,r)===e)return t;var o=r[0],s=r.slice(1),a=n(t);return s.length?a[o]=u(o in a?a[o]:{},s,e):a[o]=e,a}},function(t,r,e){"use strict";var n=e(1),i=e(3),u=function(t){return 0===Object.keys(t).length};t.exports=function o(t,r){if(i(t,r)===!1)return t;var e=r[0],s=r.slice(1),a=n(t);return s.length?(a[e]=o(t[e],s),u(a[e])&&delete a[e]):delete a[e],a}}]); | ||
module.exports=function(t){function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r,e){"use strict";function n(t,r){this._path=[],this._root=this,this._state=t}var i=e(4),u=e(5),o=e(3),s=e(1);n.prototype={getPath:function(t){return t?this._path.concat(t):this._path},getState:function(){return this._state},commit:function(t){this._root._state=t},get:function(t){return Object.create(this,{_path:{value:this.getPath(t)}})},set:function(t,r){1===arguments.length&&(r=arguments[0],t=void 0),this.commit(i(this.getState(),this.getPath(t),r))},remove:function(t){this.commit(u(this.getState(),this.getPath(t)))},has:function(t){function r(r){return t.apply(this,arguments)}return r.toString=function(){return t.toString()},r}(function(t){return s(this.getState(),this.getPath(t))}),fetch:function(t,r){return this.has(t)?this.get(t).valueOf():r},keys:function(){return Object.keys(this.valueOf()||{})},values:function(){var t=this.valueOf();return this.keys().map(function(r){return t[r]})},valueOf:function(){return o(this.getState(),this.getPath())},toJSON:function(){return this.valueOf()},toArray:function(){return this.values()},find:function(){return this.filter.apply(this,arguments)[0]}};var a=["map","reduce","filter","forEach"];a.forEach(function(t){n.prototype[t]=function(){var r;return(r=this.toArray())[t].apply(r,arguments)}}),t.exports=n},function(t,r,e){"use strict";t.exports=function(t,r){var e=!0;t:for(;e;){u=o=s=a=void 0,e=!1;var n=t,i=r,u=i[0],o=i.slice(1),s=void 0!==n,a=s&&u in n;if(o.length){if(a){t=n[u],r=o,e=!0;continue t}return!1}return a}}},function(t,r,e){"use strict";t.exports=function(t){if(Array.isArray(t))return t.slice();var r={};for(var e in t)r[e]=t[e];return r}},function(t,r,e){"use strict";var n=e(1);t.exports=function(t,r){for(var e=!0;e;){o=s=void 0,e=!1;var i=t,u=r,o=u[0],s=u.slice(1);if(!o)return i;if(n(i,u)===!1)return void 0;if(!s.length)return i[o];t=i[o],r=s,e=!0}}},function(t,r,e){"use strict";var n=e(2),i=e(3);t.exports=function u(t,r,e){if(i(t,r)===e)return t;var o=r[0],s=r.slice(1),a=n(t);return s.length?a[o]=u(o in a?a[o]:{},s,e):a[o]=e,a}},function(t,r,e){"use strict";var n=e(2),i=e(1),u=function(t){return 0===Object.keys(t).length};t.exports=function o(t,r){if(i(t,r)===!1)return t;var e=r[0],s=r.slice(1),a=n(t);return s.length?(a[e]=o(t[e],s),u(a[e])&&delete a[e]):delete a[e],a}}]); | ||
//# sourceMappingURL=Foliage.js.map |
{ | ||
"name": "foliage", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "A cursor like tree data structure.", | ||
@@ -5,0 +5,0 @@ "main": "dist/Foliage.js", |
@@ -9,7 +9,7 @@ import Foliage from '../Foliage' | ||
it ('returns a given value', function() { | ||
it ('returns cursor to a given pathway', function() { | ||
let plant = new Foliage(shallow) | ||
let query = plant.get('first') | ||
query.valueOf().should.equal(1) | ||
query.getPath().should.eql(['first']) | ||
}) | ||
@@ -32,2 +32,14 @@ | ||
describe('Foliage::fetched', function() { | ||
it ('returns a given value', function() { | ||
let plant = new Foliage(shallow) | ||
plant.fetch('first').should.equal(1) | ||
}) | ||
it ('returns a fallback if a path is not represented', function() { | ||
let plant = new Foliage() | ||
plant.fetch('first', 'fiz').should.equal('fiz') | ||
}) | ||
}) | ||
describe('Foliage::set', function() { | ||
@@ -60,2 +72,20 @@ it ('can set a new value', function() { | ||
it ('defines pathways that have not been set yet', function() { | ||
let plant = new Foliage() | ||
let query = plant.get('first') | ||
query.set('second', 'modified') | ||
plant.get([ 'first', 'second' ]).valueOf().should.equal('modified') | ||
}) | ||
it ('can set when assuming a pathway', function() { | ||
let plant = new Foliage() | ||
let query = plant.get('first') | ||
query.set('second', 'modified') | ||
plant.get([ 'first', 'second' ]).valueOf().should.equal('modified') | ||
}) | ||
}) | ||
@@ -62,0 +92,0 @@ |
@@ -8,2 +8,3 @@ /** | ||
let get = require('./get') | ||
let has = require('./has') | ||
@@ -49,2 +50,10 @@ function Foliage (state, fallback) { | ||
has(key) { | ||
return has(this.getState(), this.getPath(key)) | ||
}, | ||
fetch(key, fallback) { | ||
return this.has(key) ? this.get(key).valueOf() : fallback | ||
}, | ||
keys() { | ||
@@ -51,0 +60,0 @@ return Object.keys(this.valueOf() || {}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42074
451