foundrystore

0.1.0 • Public • Published

foundry-store

foundry-store is a general purpose state management built on FunctionFoundry and Fluxury.

It manages an object tree which may be manipulated with a formula language.

Getting Started

Option A) Install from npm.

$ npm install --save foundry-store

Require into your project.

var createStore = require('foundry-store') // Node.js / browserify / webpack
// or
import createStore from 'foundry-store' // ES6 syntax

Option B) Install from dist folder.

<html>
  <head>
    <script src="/path/to/foundry-store.js"><script>
    ...

Getting data

This library does not specify data fetching. Use jQuery, XHR, fetch, websockets and other solution to access data.

Basic Usage

var store = createStore()
store.set({ key: 'value' })
store.get('key')

store.set({ investments: [{ name: 'FundA' }, { name: 'FundB' }]})
store.filter('investments', 'EQ(name, "FundA")')
store.get('investments') // => [{ name: 'FundA' }]
store.filter('investments', 'OR(EQ(name, "FundA"), EQ(name, "FundB"))')
store.sort('investments', 'name', 'desc')
store.get('investments') // => [{ name: 'FundB' }, { name: 'FundA' }]

Advanced Usage

// Add custom query methods
var store = createStore({
  getOpen: (state) => state.investments.filter(n => n.open).map(n => n.name)
  getOpenCount: (state) => state.investments.filter(n => n.open).length
}, {
  setInvestments: (investments) => {
    this.set({ investments: investments })
  }
})

store.setInvestments([{ name: 'FundA' open: false }, { name: 'FundB', open: true }])

store.getOpen() // => ['FundB']
store.getOpenCount() // => 1

Readme

Keywords

Package Sidebar

Install

npm i foundrystore

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • petermoresi