Easy-Peasy访问其他模型
Easy-Peasy access other models
我正在使用 easy-peasy
作为 React 应用程序的状态管理器
在 actionOn
中,我需要访问另一个模型的状态,如何在 notes.onAddNote
中访问 todos.items
?
import { createStore, StoreProvider, action, actionOn } from 'easy-peasy';
const todos= {
items: [],
addTodo: action((state, text) => {
state.items.push(text)
})
};
const notes = {
items: [],
addNote: action((state, text) => {
state.items.push(text)
}),
onAddNote: actionOn(
(actions, storeActions) => storeActions.notes.addNote,
(state, target) => {
// HOW TO READ todos items
}
),
};
const models = {
todos,
notes
};
const store = createStore(models);
将 onAddNote 设为 thunkOn
而不是 actionOn
我正在使用 easy-peasy
作为 React 应用程序的状态管理器
在 actionOn
中,我需要访问另一个模型的状态,如何在 notes.onAddNote
中访问 todos.items
?
import { createStore, StoreProvider, action, actionOn } from 'easy-peasy';
const todos= {
items: [],
addTodo: action((state, text) => {
state.items.push(text)
})
};
const notes = {
items: [],
addNote: action((state, text) => {
state.items.push(text)
}),
onAddNote: actionOn(
(actions, storeActions) => storeActions.notes.addNote,
(state, target) => {
// HOW TO READ todos items
}
),
};
const models = {
todos,
notes
};
const store = createStore(models);
将 onAddNote 设为 thunkOn
而不是 actionOn