Skip to content
This repository has been archived by the owner on Oct 19, 2019. It is now read-only.

Commit

Permalink
feat: support disabled model
Browse files Browse the repository at this point in the history
  • Loading branch information
wxnet2013 committed Sep 8, 2018
1 parent bac2b8a commit 2bdaab0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export interface API {

export type Plugin = (api: API) => void;

export default function rxloopImmer(): Plugin;
export interface Config {
disabled?: string[],
}

export default function rxloopImmer(opts?: Config): Plugin;
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import produce from "immer";

export default function rxloopImmer() {
export default function rxloopImmer(
conf = {},
) {
const config = {
disabled: [],
...conf,
};
return function init() {
function createReducer(action = {}, reducer = () => {}) {
return (state) => produce(state, draft => {
function createReducer(action = {}, reducer = () => {}, model = '') {
return config.disabled.indexOf(model) > -1 ?
(state) => reducer(state, action) :
(state) => produce(state, draft => {
reducer(draft, action);
});
}
Expand Down

0 comments on commit 2bdaab0

Please sign in to comment.