Embed selectors in a Redux state tree.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.babelrc
.editorconfig
.eslintrc.json
.flowconfig
.gitattributes
.gitignore
.npmignore
.npmrc
.travis.yml
.yo-rc.json
license
package.json
readme.md
rollup.config.js

readme.md

zelektree

Build status Coverage Status

Embed selectors in a Redux state tree.

This is a convenient way for components to share selectors that are used widely throughout an app.

Inspired by Baobab.

Install

$ yarn install zelektree

Usage

import { connect, createStore, } from 'redux';
import { embedSelectors, } from 'zelektree';

const initialState = { foo: null, };

const reducer = (state = initialState) => state;

const store = createStore(
  reducer,
  // pass as the `enhancer` argument to `createStore`
  embedSelectors({
    // key each selector by intended state key name
    isFoo: (state) => !!state.foo,
  }),
);

// state and derived state are synced and merged
const state = store.getState(); // { foo: null, isFoo: false, }

API

embedSelectors(selectors)

Takes an object map of selectors and returns a Redux StoreEnhancer.

The store enhancer refreshes the selectors each time getState is called and the result is merged with the returned state.

embedSelectors expects the top-level state value to be an object. To optimize performance, this expectation is not enforced with runtime checks.

selectors

Type: { [String]: (Object) -> * }

An object map of selectors. The key for each selector is used as the state tree key for that selector's output. A selector is called with a single argument, state. state is the current state of the store.

embedSelectors is interoperable with any selector that is soley a reduction of state and not state and props, for example.

License

MIT © Max Hallinan