-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathaction.ts
More file actions
38 lines (31 loc) · 665 Bytes
/
action.ts
File metadata and controls
38 lines (31 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { createStore, action, Action, Thunk, thunk } from 'easy-peasy';
interface TodosModel {
items: string[];
add: Action<TodosModel, string>;
clear: Action<TodosModel>;
}
interface Model {
todos: TodosModel;
}
const todos: TodosModel = {
items: [],
add: action(
(state, payload) => {
state.items.push(payload);
},
{ immer: true },
),
clear: action((state) => {
state.items = [];
}),
};
const model: Model = {
todos,
};
const store = createStore(model);
store.dispatch.todos.add('foo');
// @ts-expect-error
store.dispatch.todos.add(1);
// @ts-expect-error
store.dispatch.todos.add();
store.dispatch.todos.clear();