1.0.1 • Published 6 years ago

redux-eloquent v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

redux-eloquent

redux-eloquent allows you to query and mutate your redux store in ORM style.

Usage

This simple example assumes you are familiar with using react redux and react-redux.

// Your models.js
import { defineModel, primary, id } from 'redux-eloquent'

export const Author = defineModel('authors', {
  id,           // shorthand for id: primary(Number)
  name: String
})

export const Book = defineModel('books', {
  isbn: primary(String),
  title: String,
  author: Author
})
// Your dispatch function, e.g. the callback of a request
somehowRequestBooks()
  .then(result => {
      Book(dispatch).save(result)
  })
// Your component
function mapState2Props(state) {
  return {
    allBooks: Book(state).all()
  }
}