UNPKG

4.95 kBMarkdownView Raw
1Redux CRUD Manager - v1 alpha
2===================
3
4[v0.4 docs](docs/v0.4/README.md)
5
6## Keep your redux store synced with your server.
7
8Redux CRUD Manager provide a simple way to sync your redux store with your remote server.
9No more need to write actions and reducer to update your store.
10
11* CRUD pattern
12* update local data and sync with remote server when you want
13* update local data only
14* metadata for pending action
15
16Reudx Crud Manager do not include any library around redux, and do not provide any UI component. It only provide actions and reducer.
17
18## Documentation
19
20* [Configuration](#configuration)
21* [Remote actions](docs/v1/remote-actions.md)
22* [Reducers](docs/v1/reducer.md)
23* [Metadata](docs/v1/metadata.md)
24* [Custom actions](docs/v1/custom-actions.md)
25* [Linked managers](docs/v1/linked-managers.md)
26* [Events](docs/v1/events.md)
27* [Batch actions with redux-batchted-actions](https://gist.github.com/GuillaumeJasmin/3956fb03becdba50dc18ab9a721b9793)
28
29## Configuration
30
31Install from npm registry
32```
33npm install redux-crud-manager@next --save
34```
35
36<a id="configuration"></a>
37
38```js
39import { createManager } from 'redux-crud-manager';
40
41const config = {};
42const usersManager = createManager(config);
43```
44
45### Config
46
47
48* `reducerPath` {array[string]} - required - Most of time, there is a single item: the reducer name. But if you have nested reducer, define the full path.
49
50* `idKey` {string} - optional - default `id`. The key used as the unique identifier.
51
52* `remoteActions` {object} - DEPRECATED, use `actions` instead. async action for HTTP request. See [how to configure remoteActions](docs/v1/remote-actions.md)
53
54
55* `customActions` {object} - DEPRECATED, use `actions` instead. make possible to create your own actions. See [customs actions](docs/v1//custom-actions.md)
56
57
58* `actions` {object} - See [actions](docs/v1//actions.md)
59
60
61* `cache` {bool | function} - enable cache if resources are already fetched. Default: `false`
62You can pass a function to customise the check:
63```js
64{
65 cache: (existingItems) => existingItems[0] && existingItems[0].bookId === someBookId
66}
67```
68
69
70* `merge` {bool} optional - default `true` - merge item property on update()
71
72
73* `deepMerge` {array} optional - List of properties wich need a deep merge. Currently only available for 1 depth
74
75
76* `replace` {bool} optional - default `true` . Use on fetch. If it's `true`, the previous list will be replace. if `false`, new items will be added to previous.
77
78
79* `remote` {bool} optional - default: `false` - save your change in your server, with remoteActions
80
81
82* `prefixLocalId` {string} - optional
83
84
85* `showUpdatingProgress` {bool} optional - default `true` . `syncing` will be set to `true`
86
87
88* `updateLocalBeforeRemote` {bool} optional - default `false`. Properties will be updated locally before the server response. Ignored if `showUpdatingProgress` is false
89
90
91* `includeProperties` {array[string]} optional - include property on save.
92
93
94* `excludeProperties` {array[string]} optional - include property on save. Ignored if `includeProperties` is defined
95
96
97* `linkedManagers` {array} optional - default `null`. [See example](docs/v1/linked-managers.md)
98
99
100* `enableLinkedManagers` {bool} optional - default `true` if `linkedManagers` is not null
101
102
103* `batchDispatch` {function} optional - default `(dispatch, actions) => actions.map(action => dispatch(action))`
104
105
106* `params` {object} optional - custom params used to pass arbitrary data. Use it as you want. [See example](docs/v1/remote-actions.md#custom-params)
107
108
109## Actions
110Create, update and delete
111
112```js
113import { createManager } from 'redux-crud-manager';
114const config = {};
115const userManager = createManager(config);
116
117dispatch(userManager.actions.fetchAll());
118
119dispatch(userManager.actions.fetchOne(userId));
120
121dispatch(userManager.actions.create(data, { remote: true }));
122
123dispatch(userManager.actions.update(data, { remote: true }));
124
125dispatch(userManager.actions.delete(data, { remote: true }));
126```
127
128Note: `data` can be an object or an array
129
130If you don't want to make a remote request but only use local change, set `remote: false`
131
132### PreCreate, preUpdate, preDelete
133
134You can create update and delete data locally and then save on remote.
135Its usefull when you want to do many changes and save after.
136
137```js
138dispatch(userManager.actions.preCreate(user));
139// or
140dispatch(userManager.actions.preUpdate(user));
141// or
142dispatch(userManager.actions.preDelete(user));
143
144// ...
145
146// this will save changes on remote, like actions.create(data, { remote: true })
147dispatch(userManager.actions.sync());
148
149```
150
151### Defaults actions
152* fetchAll
153* fetchOne
154* preCreate
155* create
156* preUpdate
157* update
158* preDelete
159* delete
160* sync
161* clear
162* clearChanges
163
164### Base actions
165
166Base actions are used inside `defaults actions` , and you may never have to use them. But if you need to create custom actions, you can use it.
167
168* fetching
169* fetched
170* creating
171* created
172* updating
173* updated
174* deleting
175* deleted