Module: state

Source:

Methods


<inner> createAction(name [, payloadCreator] [, metaCreator])

action creator helper that will return the redux-actions action build based on its parameters

Parameters:
Name Type Argument Default Description
name string

name of the action

payloadCreator function <optional>
getIdentityValue

method to handle the passing of the payload

metaCreator function | null <optional>
null

method to handle any additional metadata

Source:
Returns:
Type
function
Example
import {
 createModule
} from 'arco';

const module = createModule('foo');

const action = module.createAction('SET_NAME');

<inner> createAsyncAction(name, payloadHandler)

async action creator helper that creates a distinct action for each status with the status passed via payload, and injects the functions for each

Parameters:
Name Type Description
name string

name of the action

payloadHandler function

method to handle the passing of the payload

Source:
Returns:
Type
function
Example
import {
 createModule,
 get
} from 'arco';

const module = createModule('foo');

const action = module.createAsyncAction('GET_STUFF', (lifecycle, otherData) => {
 const {
   onError,
   onRequest,
   onSuccess
 } = lifecycle;

 return (dispatch) => {
   dispatch(onRequest(otherData));
   // otherData is passed as payload, PENDING is passed as status in meta

   return get('/foo')
     .then((data) => {
       dispatch(onSuccess(data));
       // data is passed as payload, SUCCESS is passed as status in meta
     })
     .catch((error) => {
       dispatch(onError(error));
       // error is passed as payload, ERROR is passed as status in meta
     });
 };
});

<inner> createModule(namespace)

create a module which has actions and a reducer, and has create methods for them

Parameters:
Name Type Description
namespace string

namespace for the module

Source:
Returns:
Type
Object
Example
import {
 createModule
} from 'arco';

const appModule = createModule('app');

<inner> createReducer(initialState, handler)

reducer creator that will accept the initialState and the handler of that function, either as standard function or as redux-actions map

Parameters:
Name Type Description
initialState Object

initial state to hydrate store with

handler function

method to handle state updates

Source:
Returns:
Type
function
Example
import {
 getCreateReducer
} from 'arco';

import module, {
 setName
} from './actions';

const INITIAL_STATE = {
 name: ''
};

const createReducer = getCreateReducer('namespace');

// use the handleActions method from redux-actions
createReducer(INITIAL_STATE, (state, {
 [setName](state, {payload}) {
   return {
     ...state,
     name: payload
   };
 }
});

// or use the traditional reducer function method, which requires converting the actions toString
createReducer(INITIAL_STATE, (state, {payload, type}) => {
 switch (type) {
   case `${setName}`:
     return {
       ...state,
       name: payload
     };

   default:
     return state;
 }
});

<inner> getModules(namespace)

get the module for the given namespace, or all modules if none

Parameters:
Name Type Description
namespace string

namespace of module to retrieve

Source:
Returns:
Type
Object
Example
import {
 getModules
} from 'arco';

const allModules = getModules();
const appModule = getModules('app');