# ActionOn

Defines an actionOn listener against your model.

# API

ActionOn<
  Model extends object = {},
  StoreModel extends object = {}
>
  • Model

    The model against which the actionOn is being defined. You need to provide this so that the state that will be provided to your actionOn is correctly typed.

  • StoreModel

    If you plan on targeting an action from another part of your store state then you will need to provide your store model so that the provided store actions are correctly typed.

# Example

import { ActionOn, actionOn } from 'easy-peasy';
import { StoreModel } from '../index';

interface AuditModel {
  logs: string[];
  onTodoAdded: ActionOn<AuditModel, StoreModel>;
}

const auditModel: AuditModel = {
  logs: [],
  onTodoAdded: actionOn(
    (actions, storeActions) => storeActions.todos.addTodo,
    (state, payload) => {
      state.logs.push(`Added todo: ${payload}`);
    }
  )
}