#981·rematch

[Question] Effects in separate files

Author: mickowalewskiCreated Feb 7, 2023Updated Sep 29, 2023
Labelsenhancement

Is there a way to write effects in separate files and then import them to the file where the createModel is executed, but with proper Typescript types? For example

bash
import { createModel } from '@rematch/core'
import incrementAsync from './effects'
import type { RootModel } from './models'
 
export const count = createModel<RootModel>()({
	state: 0,
	reducers: {
		increment(state, payload: number) {
			return state + payload
		},
	},
	effects: (dispatch) => ({
            incrementAsync: incrementAsync(dispatch),
	}),
})

incrementAsync.ts

bash
const incrementAsync = (dispatch) => (payload: number, state) => {
    dispatch.count.increment(payload)
};

export default incrementAsync;