brisky-state-get

1.0.3 • Public • Published

brisky-state-get

Build Status js-standard-style npm version Coverage Status

Get state object, using Brisky subscription notation.

var stateObj = stateGet(state, path)

Get state at path

  • state (object) - state startpoint
  • path (array) - array of keys to follow
  • {*} [set] - value to set if property is undefined (optional)
  • returns (object) stateObj - state at endpoint
const get = require('brisky-state-get')
const s = require('vigour-state/s')
 
const state = s({
  pages: {
    discover: {
      carousel: {}
    },
    shows: {
      episodes: [
        { title: 1 },
        { title: 2 },
        { title: 3 }
      ]
    }
  }
})
 
get(state, ['pages', 'discover', 'carousel']) // → state.pages.discover.carousel
 
get(state.pages.discover, ['$parent', 'shows']) // → state.pages.shows
 
get(state.pages.discover, ['$root', 'pages', 'shows']) // → state.pages.shows
 
get(state.pages.shows, ['episodes', '$any']) // → state.pages.shows.episodes
 
get(state, ['pages', '$switch']) // → state.pages
 
get(state, ['pages', '$condition']) // → state.pages
 
get(state, ['pages', 'channels'], { foo: 'bar' }).foo.compute() // → 'bar'

Dependents (1)

Package Sidebar

Install

npm i brisky-state-get

Weekly Downloads

0

Version

1.0.3

License

ISC

Last publish

Collaborators

  • vigour-io