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.25.0 to 0.100.0

dist/elements.d.ts

83

package.json
{
"name": "foliage",
"version": "0.25.0",
"description": "A cursor like tree data structure.",
"main": "src/Foliage.js",
"contributors": [
{
"name": "Nate Hunzaker",
"email": "nate.hunzaker@viget.com",
"url": "http://viget.com"
"version": "0.100.0",
"description": "Styled Components for forest",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"commit": "git-cz",
"lint": "eslint ./",
"build": "tsc --build tsconfig.json",
"format": "prettier --write \"./src/**/**.{ts,tsx,js,jsx,json}\"",
"start": "parcel example/index.html --no-cache",
"prepublishOnly": "rm -rf dist && yarn build"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"keywords": [
"styled",
"effector",
"components",
"dom"
],
"author": "Sergey Sova <mail@sergeysova.com> (https://sergeysova.com/)",
"license": "MIT",
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
],
"repository": {
"type": "git",
"url": "git://github.com/vigetlabs/foliage.git"
},
"license": "MIT",
"devDependencies": {
"@atomix/eslint-config": "^8.0.0",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@types/jest": "^25.2.1",
"@types/node": "^13.13.5",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"babel-eslint": "^10.1.0",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.2.0",
"effector": "^20.15.6",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.10.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-unicorn": "^19.0.1",
"forest": "^0.16.1",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lint-staged": "^10.2.2",
"parcel-bundler": "^1.12.4",
"prettier": "^2.0.5",
"sharec-sova-config": "^0.1.0",
"typescript": "^3.8.3",
"typescript-styled-plugin": "^0.15.0"
},
"sharec": {
"config": "sharec-sova-config",
"version": "0.1.0"
},
"dependencies": {
"diode": "~4.4"
"stylis": "^4.0.0"
},
"peerDependencies": {
"effector": "^20.15.6",
"forest": "^0.16.0"
}
}

133

README.md

@@ -1,93 +0,58 @@

![Foliage](http://f.cl.ly/items/1d0S121d301T3a202u14/foliage.svg)
# foliage
Foliage is lightweight tree that operates on a tree of JavaScript
primitives. It is inspired by many Cursors libraries/frameworks (see
[prior art](#prior-art)),
however it is not nearly as ambitious. It sacrifices robustness and
purity for the sake of embeddability.
## Usage
[![Circle CI](https://circleci.com/gh/vigetlabs/foliage.svg?style=svg)](https://circleci.com/gh/vigetlabs/foliage)
```ts
import { using } from 'forest';
import { styled, StyledRoot } from 'foliage';
---
const Block = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
color: white;
box-shadow: rgba(0, 0, 0, 0.17) 0px 2px 20px;
box-sizing: border-box;
min-height: 100vh;
margin-bottom: 160px;
background: linear-gradient(20deg, rgb(219, 112, 147), rgb(218, 163, 87));
`;
## Goals
const Button = styled.a`
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white;
text-decoration: none;
1. Easier testing. Decouple React components from rest of app. 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.
## Opinions
1. Keep a naming convention similar to ES6 maps
2. Don't do too much, but provide a platform for extension
## Working with Foliage
Foliage can retrieve and set data similarly to an ES6 map
```javascript
let plant = new Foliage({ berries: true })
// retrieve state
plant.get('berries') // true
// set state
plant.set('berries', false)
// remove state
plant.remove('berries')
```
### Working with subsets of data
`refine` will clone an instance of Foliage and place a cursor to a
point within its tree:
```javascript
let plant = new Foliage({ berries: true })
plant.refine('berries').valueOf() // => true
```
```javascript
let oak = new Foliage({
squirrels: {
squeakem: { weight: 2, height: 12 }
chatters: { weight: 5, height: 8 }
&[data-fill='true'] {
background: white;
color: palevioletred;
}
})
`;
let squirrels = oak.refine('squirrels')
```
function App() {
Block({
fn() {
Button({
text: 'Google',
attr: { href: 'https://google.com' },
data: { fill: true },
});
Button({
text: 'Yandex',
attr: { href: 'https://yandex.ru' },
});
},
});
}
In this example, `squirrels` is a subset of `oak` focused on the
`squirrels` key. Under the hood, they point to the same underlying
data. This means if you `set` in `squirrel`, `oak` will be modified as
well:
```javascript
squirrels.set(['squeakem', 'weight'], 5)
oak.get(['squirrels', 'squeakem', 'weight']) // => 5
using(document.querySelector('#root'), App);
using(document.querySelector('head'), StyledRoot));
```
A couple of things are going on here. First, `set` is used to modify
data. Second, both `get` and `set` accept an array of keys. When given
an array, they will traverse the tree for the leaf value instead of
just returning the key from the most immediate level.
## Prior art
There is nothing novel about Foliage, it shamelessly mimics:
- [Sprout](https://github.com/herrstucki/sprout)
- [OmnicientJS](http://omniscientjs.github.io/)
- [OmnicientJS Immstruct](https://github.com/omniscientjs/immstruct)
- [Om](https://github.com/omcljs/om)
- [Functional Zippers](http://yquem.inria.fr/~huet/PUBLIC/zip.pdf)
- [React Cursor](https://github.com/dustingetz/react-cursor)
- [Baobab](https://github.com/Yomguithereal/baobab)
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