data-adapter-js
You can use it to adapting data in according to a schema for Flux and Redux apps.
Install
$ npm install data-adapter-js --save-dev
Require
Run
$ npm start$ npm test$ npm run build$ npm run lint
API
ArrayOf Parameters:
- Model
- array of data
InstanceOf Parameters:
- Model
- object
Model Parameters:
- pluralize name
- adapter function ( current, parrent )
Demo
const User = 'users' id: userid username: username comments : Comment usercomments const Comment = 'comments' id: commentid userId: userid text: commentcontent const Post = 'posts' id: postid user: User postauthor text: postcontent
Data
before
id: 1 name: 'toto' comments : id: 31 postId: 1 content : 'lorem ipsum elms' id: 39 postId: 1 content : 'dare ipsum remu' id: 2 name: 'tata' comments : id: 34 postId: 4 content : 'lorem ipsum elms' id: 32 postId: 15 content : 'dare ipsum remu'
After
users: 1: id: 1 username: 'toto' comments : 31 39 2: id: 2 username: 'tata' comments : 34 32 comments: 31: id: 31 userId: 1 text: 'lorem ipsum elms' 39: id: 39 userId: 1 text: 'dare ipsum remu' 34: id: 34 serId: 2 text: 'lorem ipsum elms' 32: id: 32 userId: 2 text: 'dare ipsum remu'