Search code examples
javascriptreactjseasy-peasy

Easy-Peasy access other models


I am using easy-peasy as the state manager of react application In the actionOn I need to access state of another model, How can I access todos.items in the notes.onAddNote ?

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);


Solution

  • making onAddNote a thunkOn instead of actionOn