How to use the easy-peasy.createStore 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 / action.ts View on Github external
const todos: TodosModel = {
  items: [],
  add: action((state, payload) => {
    state.items.push(payload);
  }),
  clear: action(state => {
    state.items = [];
  }),
};

const model: Model = {
  todos,
};

const store = createStore(model);

store.dispatch.todos.add('foo');
// typings:expect-error
store.dispatch.todos.add(1);
// typings:expect-error
store.dispatch.todos.add();

store.dispatch.todos.clear();

interface ListeningModel {
  logs: string[];
}

interface TargetModel {
  doAction: Action;
  doThunk: Thunk;
github ctrlplusb / easy-peasy / src / __tests__ / typescript / thunk.ts View on Github external
injections.fetch().then(() => 'done');
        dispatch({ type: 'FOO' });
        getStoreActions().audit.log('foo');
        meta.parent.concat(['foo']);
        meta.path.concat(['foo']);
        return 1;
      },
    ),
    syncThunk: thunk((actions, payload) => {
      return 'Woot!';
    }),
    empty: thunk(() => {}),
  },
};

const store = createStore(model);

store
  .getActions()
  .audit.syncThunk()
  .toUpperCase();
store
  .getActions()
  .audit.log('foo')
  .then(result => result + 1);
// typings:expect-error
store.getActions().audit.log(1);
// typings:expect-error
store.getActions().audit.log();

store.getActions().audit.empty();
// typings:expect-error
github ctrlplusb / easy-peasy / src / __tests__ / typescript / store.ts View on Github external
interface PersistPartial {
  persist: string;
}

function persistReducer(
  baseReducer: Reducer,
): Reducer<s> {
  return (baseReducer as unknown) as Reducer<s>;
}

const store = createStore(model, {
  reducerEnhancer: reducer =&gt; persistReducer(reducer),
});

const configuredStore = createStore(model, {
  disableImmer: false,
  devTools: false,
  initialState: { foo: 'bar' },
  injections: { foo: 'bar' },
  mockActions: true,
  name: 'bob',
  reducerEnhancer: reducer =&gt; reducer,
});

store.getActions().doActionVoid();

store.getActions().doAction(true);
store.dispatch.doAction(true);

// typings:expect-error
store.getActions().doAction(1);</s></s>
github ctrlplusb / easy-peasy / src / __tests__ / typescript / selector.ts View on Github external
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
store.getState().todos.getById('foo');

const todo = store.getState().todos.getById(1);

// typings:expect-error
todo.text + 'foo';
github monsieurBoutte / react-pwa-boilerplate / src / configureStore.js View on Github external
import { composeWithDevTools } from 'redux-devtools-extension';
import { createStore } from 'easy-peasy';
import { model } from './models';

/**
 * model, is used for passing through the base model
 * the second argument takes an object for additional configuration
 */

const store = createStore(model, {
  compose: composeWithDevTools({ realtime: true, trace: true })
  // initialState: {}
});

export default store;
github jamaljsr / polar / src / store / models / designer.spec.ts View on Github external
beforeEach(() => {
    // reset the store before each test run
    store = createStore(rootModel, { injections });
  });
github jamaljsr / polar / src / store / models / lightning.spec.ts View on Github external
designer: designerModel,
  };
  const network = getNetwork();
  const initialState = {
    network: {
      networks: [network],
    },
    designer: {
      activeId: 1,
      allCharts: {
        1: initChartFromNetwork(network),
      },
    },
  };
  // initialize store for type inference
  let store = createStore(rootModel, { injections, initialState });
  const node = initialState.network.networks[0].nodes.lightning[0] as LndNode;

  beforeEach(() => {
    // reset the store before each test run
    store = createStore(rootModel, { injections, initialState });

    asyncUtilMock.delay.mockResolvedValue(Promise.resolve());
    bitcoindServiceMock.sendFunds.mockResolvedValue('txid');
    lightningServiceMock.getNewAddress.mockResolvedValue({ address: 'bc1aaaa' });
    lightningServiceMock.getInfo.mockResolvedValue(
      defaultStateInfo({
        alias: 'my-node',
        pubkey: 'abcdef',
        syncedToChain: true,
      }),
    );
github ctrlplusb / easy-peasy / src / __tests__ / typescript / issue87.ts View on Github external
interface IModel {
  animal: IAnimal;
  setAnimal: Action;
}

const model: IModel = {
  animal: {
    name: 'robert',
  },
  setAnimal: action((state, payload) =&gt; {
    return { ...state, animal: payload.animal };
  }),
};

const store = createStore(model);
github pterodactyl / panel / resources / scripts / state / index.ts View on Github external
import user, { UserStore } from '@/state/user';
import permissions, { GloablPermissionsStore } from '@/state/permissions';

export interface ApplicationStore {
    permissions: GloablPermissionsStore;
    flashes: FlashStore;
    user: UserStore;
}

const state: ApplicationStore = {
    permissions,
    flashes,
    user,
};

export const store = createStore(state);
github moltin / shopkit / src / index.js View on Github external
}

  const buttons = [...document.querySelectorAll('.moltin-buy-button')]
  const cartBtns = [...document.querySelectorAll('.moltin-cart-button')]
  const loginBtns = [...document.querySelectorAll('.moltin-login-button')]

  const cart = document.createElement('div')
  document.body.appendChild(cart)

  const api = new MoltinClient({
    client_id,
    application: 'moltin-btn',
    ...(currency &amp;&amp; { currency })
  })

  const store = createStore(model, {
    injections: {
      api
    }
  })

  buttons.forEach(el =&gt;
    ReactDOM.render(
      
        
          
        
      ,
      el
    )
  )