redux-object
Builds complex JS object from normalized redux store. Best works with json-api-normalizer.
DEMO - https://yury-dymov.github.io/json-api-react-redux-example/
Demo sources and description - https://github.com/yury-dymov/json-api-react-redux-example
API
Library provides build
function, which takes 4 parameters: redux state part, object type, ID or an array of IDs or null, and options.
If ID is provided in a form of array, multiple objects are fetched. If ID is null, all objects of selected type are fetched.
Option | Default | Description |
---|
eager | false | Controls lazy loading for the child relationship objects. By default, lazy loading is enabled. |
ignoreLinks | false | redux-object doesn't support remote objects. This option suppresses the exception thrown in case user accesses a property, which is not loaded to redux store yet. |
includeType | false | Include the record type as a property 'type' on each result. This is particularly useful for identifying the record type returned by a polymorphic relationship. |
import build from 'redux-object';
const post = build(state.data, 'post', '2620');
console.log(post.id);
console.log(post.text);
console.log(post.daQuestion);
console.log(post.liker.length);
console.log(post.liker[0]);
const post = build(state.data, 'post', '2620', { eager: true });
const post = build(state.data, 'post', '2620', { eager: false, ignoreLinks: true });
Child objects are lazy loaded unless eager option is explicitly provided.
License
MIT (c) Yury Dymov
Version 0.5.4 (5th November 2017)
Private cache attributes are not enumerable for object returned by build
(https://github.com/yury-dymov/redux-object/pull/31)