Skip to content

Mixin for `redux-models`. Mixin adds CRUD-methods to models.

Notifications You must be signed in to change notification settings

vshushkov/redux-models-mixin-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-models-mixin-crud

Mixin for redux-models. Mixin adds CRUD-methods to models.

Usage

methods.js

export default {
  create() { ... POST / },
  updateById() { ... PATCH /:id },
  deleteById() { ... DELETE /:id },
  find() { ... GET / }
  findById() { ... GET /:id }
};

user.js

import { createModel } from 'redux-models-creator';
import crudMixin from 'redux-models-mixin-crud';
import methods from './methods';

const user = createModel({
  name: 'user',
  mixins: [
    crudMixin({ methods })
  ]
});

export const reducer = user.reducer;
export default user;

Or you may pass to-api instance:

api.js

import apiCreator from 'to-api';

const creator = apiCreator({ baseUrl: process.env.BASE_URL });
export default creator;

user.js

import { createModel } from 'redux-models-creator';
import crudMixin from 'redux-models-mixin-crud';
import api from './api';

const baseUrl = `${api.baseUrl}/users`;

const user = createModel({
  name: 'user',
  mixins: [
    crudMixin({ apiCreator: api, baseUrl })
  ]
})

export const reducer = user.reducer;
export default user;

About

Mixin for `redux-models`. Mixin adds CRUD-methods to models.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published