redux-object
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}function o(t,e,r){var n={},i=t[e][r.toString()];return i&&((0,u.default)(i.attributes).forEach(function(t){n[t]=i.attributes[t]}),i.relationships&&(0,u.default)(i.relationships).forEach(function(e){Object.defineProperty(n,e,{get:function(){var r="__"+e;if(n[r])return n[r];var u=i.relationships[e];if(u.id){var a=u.id.split(",");1===a.length?n[r]=o(t,u.type,a[0]):n[r]=a.map(function(e){return o(t,u.type,e)})}else n[r]=[];return n[r]}})})),n}Object.defineProperty(e,"__esModule",{value:!0}),e.default=o;var i=r(2),u=n(i)},function(t,e){t.exports=require("lodash/keys")}]); | ||
module.exports=function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}function o(t,e,r){var n=r.toString(),i={},a=t[e][n];return a&&((0,u.default)(a.attributes).forEach(function(t){i[t]=a.attributes[t]}),a.relationships&&(0,u.default)(a.relationships).forEach(function(e){Object.defineProperty(i,e,{get:function(){var r="__"+e;if(i[r])return i[r];var n=a.relationships[e];if(n.id){var u=n.id.split(",");1===u.length?i[r]=o(t,n.type,u[0]):i[r]=u.map(function(e){return o(t,n.type,e)})}else i[r]=[];return i[r]}})})),(0,s.default)(i,"id")||(i.id=n),i}Object.defineProperty(e,"__esModule",{value:!0}),e.default=o;var i=r(3),u=n(i),a=r(2),s=n(a)},function(t,e){t.exports=require("lodash/has")},function(t,e){t.exports=require("lodash/keys")}]); |
{ | ||
"name": "redux-object", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Builds complex JS object from normalized redux store. Best works with json-api-normalizer", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
# redux-object | ||
[![npm version](https://img.shields.io/npm/v/redux-object.svg?style=flat)](https://www.npmjs.com/package/redux-object) | ||
[![Downloads](http://img.shields.io/npm/dm/redux-object.svg?style=flat-square)](https://npmjs.org/package/redux-object) | ||
[![Build Status](https://img.shields.io/travis/yury-dymov/redux-object/master.svg?style=flat)](https://travis-ci.org/yury-dymov/redux-object) | ||
[![Coverage Status](https://coveralls.io/repos/github/yury-dymov/redux-object/badge.svg?branch=master)](https://coveralls.io/github/yury-dymov/redux-object?branch=master) | ||
Builds complex JS object from normalized redux store. Best works with [json-api-normalizer](https://github.com/yury-dymov/json-api-normalizer). | ||
DEMO - [https://yury-dymov.github.io/json-api-react-redux-example/](https://yury-dymov.github.io/json-api-react-redux-example/) | ||
Demo sources and description - [https://github.com/yury-dymov/json-api-react-redux-example](https://github.com/yury-dymov/json-api-react-redux-example) | ||
# API | ||
Library provides `build` function, which takes 3 parameters: state part, object type and ID. | ||
```JavaScript | ||
import build from 'redux-object'; | ||
/* | ||
state: | ||
{ | ||
data: { | ||
post: { | ||
"2620": { | ||
attributes: { | ||
"text": "hello", | ||
"id": 2620 | ||
}, | ||
relationships: { | ||
daQuestion: { | ||
id: "295", | ||
type: "question" | ||
}, | ||
liker: { | ||
id: "1,2,3", | ||
type: "user" | ||
}, | ||
comments: {} | ||
} | ||
} | ||
}, | ||
question: { | ||
"295": { | ||
attributes: { | ||
text: "hello?" | ||
} | ||
} | ||
}, | ||
user: { | ||
"1": { | ||
attributes: { | ||
id: 1, | ||
name: "Alice" | ||
} | ||
}, | ||
"2": { | ||
attributes: { | ||
id: 2, | ||
name: "Bob" | ||
} | ||
}, | ||
"3": { | ||
attributes: { | ||
id: 3, | ||
text: "Jenny" | ||
} | ||
} | ||
}, | ||
meta: { | ||
'posts/me': { | ||
data: { | ||
post: '2620' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
*/ | ||
const post = build(state.data, 'post', '2620'); | ||
console.log(post.id); // -> 2620 | ||
console.log(post.text); // -> hello | ||
console.log(post.daQuestion); // -> { id: 295, text: "hello?" } | ||
console.log(post.liker.length); //-> 3 | ||
console.log(post.liker[0]); // -> { id: 1, name: "Alice" } | ||
``` | ||
Child objects are lazy loaded. | ||
# License | ||
MIT (c) Yury Dymov |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6079
94