How to use the @rematch/core.createModel function in @rematch/core

To help you get started, we’ve selected a few @rematch/core 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 modularcode / modular-material-admin-react-pro / src / _store / redux / userStore.tsx View on Github external
import { createModel, RematchDispatch } from '@rematch/core'
import User from '_types/User'
import usersService from '_api/rest/usersService'

export interface UserState extends User {}

const model = createModel({
  state: null,
  reducers: {
    set: (state: UserState, payload: User): UserState => payload,
  },
  effects: (dispatch: RematchDispatch) => ({
    async request() {
      const currentUser = await usersService.getProfile()

      // dispatch.user.set(currentUser)
      // this.set(currentUser)
      dispatch.user.set(currentUser)
    },
    // TODO: Optional args breaks TypeScript autocomplete (e.g. payload: number = 1)
    // async incrementAsync(payload: number) {
    //   await delay(500);
    //   this.increment(payload || 1);
github springtype-org / springtype / src / packages / state / src / StateManager.ts View on Github external
static addModel(stateModel: any, modelConfig: Rematch.Model): any {

        let store = StateManager.getStore();

        // automatically create singleton store
        if (!store) {
            store = StateManager.createStore();
        }
        store.model(modelConfig);

        Reflect.set(stateModel, MODEL, Rematch.createModel(modelConfig));
    }
github rematch / rematch / examples / react / count / src / models.js View on Github external
import { createModel } from '@rematch/core';

export const count = createModel({
  state: 0,
  reducers: {
    increment: s => s + 1
  },
  effects: {
    async asyncIncrement() {
      await new Promise((resolve) => {
        setTimeout(resolve, 1000)
      })
      this.increment()
    }
  },
})
github springtype-org / springtype / src / packages / state / src / StateManager.ts View on Github external
static createModel(stateModel: any, modelConfig: Rematch.Model): any {
        Reflect.set(stateModel, MODEL, Rematch.createModel(modelConfig));
    }
github rematch / rematch / examples / ts / count / src / models / sharks.ts View on Github external
const model = {
	state: 0,
	reducers: {
		increment: (state: SharksState, payload: number): SharksState =>
			state + payload,
	},
	effects: (dispatch: Dispatch) => ({
		async incrementAsync(payload: number = 1) {
			await delay(500)
			dispatch.sharks.increment(payload)
		},
	}),
}

export const sharks: typeof model = createModel(model)
github modularcode / modular-material-admin-react-pro / src / _state / appModel.ts View on Github external
}

export interface AppStateData {
  user?: User
}
export interface AppState extends AppStateStatus {
  data: AppStateData
}

const initialState: AppState = {
  loading: true,
  error: undefined,
  data: {},
}

const model = createModel({
  state: initialState,
  reducers: {
    setStatus: (
      state: AppState,
      payload: { loading?: boolean; error?: any },
    ): AppState => ({
      ...state,
      ...payload,
    }),
    setData: (state: AppState, payload: AppStateData): AppState => ({
      ...state,
      data: {
        ...state.data,
        ...payload,
      },
    }),
github rematch / rematch / examples / ts / count / src / models / dolphins.ts View on Github external
export type DolphinsState = number

const model = {
	state: 0,
	reducers: {
		increment: (state: DolphinsState) => state + 1,
	},
	effects: (dispatch: Dispatch) => ({
		async incrementAsync() {
			await delay(500)
			dispatch.dolphins.increment()
		},
	}),
}

export const dolphins: typeof model = createModel(model)