1.0.5 • Published 5 years ago

redux-action-type v1.0.5

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

redux-action-type

Tiny library for using js/ts classes as action creators

// Just extends action class and set static 
// field to instance field on initialization
@Action()
class MyAction {
	/**
	* Static type field which will be converted to property on new MyAction()
	*/
	static type = 'type'
}

// somewhere in reducer file
// if typescriot there you can:
// action: TypedAction<T>
const myReducer = (state, action) => {
	switch(action.type) {
		case MyAction.type: {
			// do something
		}
		// ...
	}
}

Also because redux does't support nothing but object in dispatch by default there is reduxActionTypeMiddleware - just converts class instances to plain object to overpass it

import { reduxActionTypeMiddleware } from 'redux-action-type'
// apply mw to your store to use classes
createStore(reducer, applyMiddleware(reduxActionTypeMiddleware))

Also for typescript. Lib has redefinition of redux dispatch that allows to pass anything in dispatch ( because with cannot track fields added dynamically so it's only way to overpass it )

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago