How to use the easy-peasy.selector function in easy-peasy

To help you get started, we’ve selected a few easy-peasy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ctrlplusb / easy-peasy / src / __tests__ / typescript / selector.ts View on Github external
status: StatusModel;
}

const model: StoreModel = {
  todos: {
    items: [],
    count: selector([state => state.items], ([items]) => {
      return items.length;
    }),
    getById: selector([state => state.items], ([items], [id]) => {
      return items.find(x => x.id === id);
    }),
    unTypedArgs: selector([state => state.items], ([items]) => items.length),
  },
  status: {
    totalTodos: selector(
      [(state, storeState) => storeState.todos.count],
      ([count]) => count(),
    ),
  },
};

const store = createStore(model);

const count = store.getState().todos.count();

count + 1;

// typings:expect-error
store.getState().todos.getById();

// typings:expect-error
github ctrlplusb / easy-peasy / src / __tests__ / typescript / selector.ts View on Github external
interface StoreModel {
  todos: TodosModel;
  status: StatusModel;
}

const model: StoreModel = {
  todos: {
    items: [],
    count: selector([state => state.items], ([items]) => {
      return items.length;
    }),
    getById: selector([state => state.items], ([items], [id]) => {
      return items.find(x => x.id === id);
    }),
    unTypedArgs: selector([state => state.items], ([items]) => items.length),
  },
  status: {
    totalTodos: selector(
      [(state, storeState) => storeState.todos.count],
      ([count]) => count(),
    ),
  },
};

const store = createStore(model);

const count = store.getState().todos.count();

count + 1;

// typings:expect-error
github ctrlplusb / easy-peasy / src / __tests__ / typescript / selector.ts View on Github external
number,
    [SelectorRef],
    [],
    StoreModel
  >;
}

interface StoreModel {
  todos: TodosModel;
  status: StatusModel;
}

const model: StoreModel = {
  todos: {
    items: [],
    count: selector([state => state.items], ([items]) => {
      return items.length;
    }),
    getById: selector([state => state.items], ([items], [id]) => {
      return items.find(x => x.id === id);
    }),
    unTypedArgs: selector([state => state.items], ([items]) => items.length),
  },
  status: {
    totalTodos: selector(
      [(state, storeState) => storeState.todos.count],
      ([count]) => count(),
    ),
  },
};

const store = createStore(model);
github ctrlplusb / easy-peasy / src / __tests__ / typescript / selector.ts View on Github external
StoreModel
  >;
}

interface StoreModel {
  todos: TodosModel;
  status: StatusModel;
}

const model: StoreModel = {
  todos: {
    items: [],
    count: selector([state => state.items], ([items]) => {
      return items.length;
    }),
    getById: selector([state => state.items], ([items], [id]) => {
      return items.find(x => x.id === id);
    }),
    unTypedArgs: selector([state => state.items], ([items]) => items.length),
  },
  status: {
    totalTodos: selector(
      [(state, storeState) => storeState.todos.count],
      ([count]) => count(),
    ),
  },
};

const store = createStore(model);

const count = store.getState().todos.count();