I suggest action creators should cache and return corresponding namedtuple for the same action name in order to combine best practices from Javscript (JS) and Python (PY).
In Javascript, files for reducers, actions are placed separately while the single dispatch mechanism in python requires the same object reference.
Currently, in order to glue up reducers and actions, I have to do something below
from pyredux import default_reducer
from pyrsistent import pmap
import xxx.actions.common as Common
import xxx.constants as CONST
DEFAULT_STATE = {
'isLoading': False,
}
@default_reducer
def main(action, state=pmap(DEFAULT_STATE)):
return state
@main.register(Common.TYPES[CONST.TYPES['UPDATE_IS_LOADING']])
def updateIsLoading(action, state):
return state.set('isLoading', action.payload)
import pyredux
import xxx.constants as CONST
TYPES = {
CONST.TYPES['UPDATE_IS_LOADING']: pyredux.create_action_type(
CONST.TYPES['UPDATE_IS_LOADING']
),
}
def updateIsLoading(isLoading=False):
return TYPES[CONST.TYPES['UPDATE_IS_LOADING']](isLoading)
It it little bit tedious for exposing those TYPES as they need to be same reference for single dispatch?
I am wondering if the built-in action creator provide a caching mechanism I can simply create an action object every time instead of caching them myself
I suggest action creators should cache and return corresponding
namedtuplefor the same action name in order to combine best practices from Javscript (JS) and Python (PY).In Javascript, files for
reducers,actionsare placed separately while the single dispatch mechanism in python requires the same object reference.Currently, in order to glue up
reducersandactions, I have to do something belowreducers/common.pyactions/common.pyIt it little bit tedious for exposing those
TYPESas they need to be same reference forsingle dispatch?I am wondering if the built-in
action creatorprovide a caching mechanism I can simply create an action object every time instead of caching them myself