Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

foliage

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foliage - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

src/__tests__/dissoc.test.js

13

CHANGELOG.md
# Changelog
## 5.0.0
## 0.6.0
- Makes better use of internal methods to reduce file size
- Dissoc no longer automatically prunes empty objects
```
Uglified : 2.13kb
Gzipped : 0.88kb
```
## 0.5.0
- Added `fetch`, which will return a pathway and allow a fallback if it doesn't exist

@@ -6,0 +17,0 @@

2

dist/Foliage.js

@@ -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(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}}]);
module.exports=function(t){function r(e){if(n[e])return n[e].exports;var i=n[e]={exports:{},id:e,loaded:!1};return t[e].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var n={};return r.m=t,r.c=n,r.p="",r(0)}([function(t,r,n){function e(t){this._path=[],this._root=this,this._state=t}var i=n(4),o=n(5),u=n(2);e.prototype={getPath:function(t){return t?this._path.concat(t):this._path},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._state,this.getPath(t),r))},remove:function(t){this.commit(o(this._state,this.getPath(t)))},fetch:function(t,r){var n=this.get(t).valueOf();return void 0===n?r:n},keys:function(){return Object.keys(this.valueOf()||{})},values:function(){return this.keys().map(this.fetch,this)},valueOf:function(){return u(this._state,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){e.prototype[t]=function(){var r;return(r=this.toArray())[t].apply(r,arguments)}}),t.exports=e},function(t,r,n){t.exports=function(t){if(Array.isArray(t))return t.slice();var r={};for(var n in t)r[n]=t[n];return r}},function(t,r,n){var e=n(3);t.exports=function(t,r){for(var n=!0;n;){u=s=void 0,n=!1;var i=t,o=r,u=o[0],s=o.slice(1);if(!u)return i;if(e(i,o)===!1)return void 0;if(!s.length)return i[u];t=i[u],r=s,n=!0}}},function(t,r,n){t.exports=function(t,r){var n=!0;t:for(;n;){o=u=s=a=void 0,n=!1;var e=t,i=r,o=i[0],u=i.slice(1),s=void 0!==e,a=s&&o in e;if(u.length){if(a){t=e[o],r=u,n=!0;continue t}return!1}return a}}},function(t,r,n){var e=n(1),i=n(2);t.exports=function o(t,r,n){if(i(t,r)===n)return t;var u=r[0],s=r.slice(1),a=e(t);return s.length?a[u]=o(u in a?a[u]:{},s,n):a[u]=n,a}},function(t,r,n){var e=n(1),i=n(3);t.exports=function o(t,r){if(i(t,r)===!1)return t;var n=r[0],u=r.slice(1),s=e(t);return u.length?s[n]=o(t[n],u):delete s[n],s}}]);
//# sourceMappingURL=Foliage.js.map
{
"name": "foliage",
"version": "0.5.0",
"version": "0.6.0",
"description": "A cursor like tree data structure.",

@@ -5,0 +5,0 @@ "main": "dist/Foliage.js",

@@ -12,9 +12,8 @@ [![NPM](https://nodei.co/npm/foliage.png?compact=true)](https://npmjs.org/package/foliage)

Foliage is lightweight
[zipper](http://en.wikipedia.org/wiki/Zipper_%28data_structure%29)
that operates on a tree of JavaScript primitives. It is modeled
Foliage is lightweight tree that operates on a tree of JavaScript primitives. It is modeled
loosely on [Om's Cursor](https://github.com/omcljs/om/wiki/Cursors)
and
[OmniscientJS's `immstruct`](https://github.com/omniscientjs/immstruct),
however it is not nearly as ambitious.
however it is not nearly as ambitious. It compromises on robustness
and purity for the benefit of build size.

@@ -27,7 +26,16 @@ Foliage makes it easier to work with data in component-oriented

## What problems does it attempt to solve?
## Goals
1. Decouple React components from rest of app. Our Flux-like framework, [Microcosm](https://github.com/vigetlabs/microcosm), keeps all state in a single app instance. It can be troublesome to pass down this context to child components that need to modify state. Foliage makes it easier to "branch" off a subset of data while still having the ability to reference the root.
2. Data traversal. It is simpler to run queries for specific records on objects, with a query like data.users[params.id]. However JavaScript objects aren't good at enumeration. Foliage provides some helpers out of the box for this.
3. It is small. Foliage isn't trying to do too much or be too smart. Like [Microcosm](https://github.com/vigetlabs/microcosm), it will be embedded in other tools and should be as small as possible.
1. Easier testing. Decouple React components from rest of app. Our
Flux-like framework,
[Microcosm](https://github.com/vigetlabs/microcosm), keeps all
state in a single app instance. It can be troublesome to pass down
this context to child components that need to modify state. Foliage
makes it easier to "branch" off a subset of data while still having
the ability to reference the root.
2. Easy data traversal. It is simple to traverse object keys, however
JavaScript objects aren't good at enumeration. Foliage provides
some helpers out of the box for this.
3. Keep it less than 1kb gzipped. Foliage isn't trying to do too much
or be too smart.

@@ -37,4 +45,3 @@ ## Opinions

1. Keep a naming convention similar to ES6 maps
2. Keep it small. There are plenty of other Cursors-like
libraries. See [Prior Art](#prior-art)
2. Don't do too much, but provide a platform for extension

@@ -41,0 +48,0 @@ ## Working with Foliage

let copy = require('./copy')
let has = require('./has')
let isEmpty = function(obj) {
return Object.keys(obj).length === 0
}
module.exports = function dissoc (obj, keys) {

@@ -18,6 +14,2 @@ if (has(obj, keys) === false) {

clone[head] = dissoc(obj[head], tail)
if (isEmpty(clone[head])) {
delete clone[head]
}
} else {

@@ -24,0 +16,0 @@ delete clone[head]

@@ -8,5 +8,4 @@ /**

let get = require('./get')
let has = require('./has')
function Foliage (state, fallback) {
function Foliage (state) {
this._path = []

@@ -23,6 +22,2 @@ this._root = this

getState() {
return this._state
},
commit(state) {

@@ -44,15 +39,12 @@ this._root._state = state

this.commit(assoc(this.getState(), this.getPath(key), value))
this.commit(assoc(this._state, this.getPath(key), value))
},
remove(key) {
this.commit(dissoc(this.getState(), this.getPath(key)))
this.commit(dissoc(this._state, this.getPath(key)))
},
has(key) {
return has(this.getState(), this.getPath(key))
},
fetch(key, fallback) {
return this.has(key) ? this.get(key).valueOf() : fallback
let val = this.get(key).valueOf()
return val === undefined ? fallback : val
},

@@ -65,8 +57,7 @@

values() {
let value = this.valueOf()
return this.keys().map(k => value[k])
return this.keys().map(this.fetch, this)
},
valueOf() {
return get(this.getState(), this.getPath())
return get(this._state, this.getPath())
},

@@ -73,0 +64,0 @@

@@ -18,4 +18,2 @@ var Webpack = require('webpack')

plugins: [],
resolve: {

@@ -35,3 +33,4 @@ extensions: [ '', '.js', '.jsx', '.json' ],

stage : 1,
loose : true
loose : true,
blacklist : [ "useStrict" ]
}

@@ -38,0 +37,0 @@ }]

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc