A helper function to create action creators that can create actions interpretable by urlQueryMiddleware and urlQueryReducer. The standard format of an action produced by the action creators this function creates is:
{
type: actionType,
meta: {
...meta,
urlQuery: true
},
payload: payload
}
actionType
(String): The standard redux action type, maps totype
in the action.- [
payload
] (Function): Takes the arguments provided from the action creator and produces what ends up inpayload
in the action. Can return any type. It defaults to the identity function. - [
meta
] (Function): Takes the arguments provided from the action creator and produces what ends up inmeta
in the action. It must return an object, otherwise it will show up undermeta.value
.
(Function): An action creator that will produce an action that is recognizable by urlQueryMiddleware and urlQueryReducer.
const changeFoo = urlAction('CHANGE_FOO', foo => ({ encodedValue: String(foo) }));
dispatch(changeFoo(94));
/*
dispatches action of form:
{
type: 'CHANGE_FOO',
meta: {
urlQuery: true
},
payload: {
encodedValue: '94'
}
}
*/
const changeBar = urlAction(
'CHANGE_BAR',
bar => bar,
bar => ({ updateType: UrlUpdateTypes.pushIn })
);
dispatch(changeBar('some-bar-value'));
/*
dispatches action of form:
{
type: 'CHANGE_BAR',
meta: {
urlQuery: true,
updateType: UrlUpdateTypes.pushIn
},
payload: 'some-bar-value'
}
*/