actions

Methods

(inner) actionCreator(payloadopt, metaopt) → {Object}

Takes an optional payload and meta object and returns an object that describes a redux action to be dispatched

A empty object default functino is used for both meta and payload to handle cases where a null is passed as either rather than an undefined

Parameters:
Name Type Attributes Description
payload Object <optional>

payload data this action

meta Object <optional>

meta data for this action

Source:
Returns:

includes a type string, and optional payload and meta objects

Type
Object
Example
const payload = { soundTrack: 'Jurrasic Park' }
beginGoodTimes(payload)
//=> {
//  type: '@@/actionTypes/gootTimes',
//  payload: { soundTrack: 'Jurrasic Park' },
//  meta: {},
//}

const meta = { initiatedBy: 'Dr. Malcom' }
beginGoodTimes(payload, meta)
//=> {
//  type: '@@/actionTypes/gootTimes',
//  meta: { initiatedBy: 'Dr. Malcom' },
//  payload: { soundTrack: 'Jurrasic Park' },
//}

(inner) actionTypeIs(action, type) → {Boolean}

Given an action and a type string, returns a boolean value to indicate that the action has a type property equal to to the type string

Parameters:
Name Type Description
action Object

standard action object

type String

any string

Source:
See:
  • tests

Returns:

true if action.type === type

Type
Boolean
Example
const type = 'test'
const action = { type }

actionTypeIs(action, 'test')
//=> true

actionTypeIs(action, 'blah')
//=> false

const thunk = () => {}
actionTypeIs(thunk, 'test')
//=> false

actionTypeIs({}, 'test')
//=> false

(inner) createAction(type) → {actionCreator}

Given the specified type, return a function that creates an object with a specified type, and assign its arguments to a payload object

Parameters:
Name Type Description
type String

redux action type name

Source:
See:
  • tests

Returns:

Action creator function that applys a payload and returns an object of the given action type with the given payload

Type
actionCreator
Example
const BEGIN_GOOD_TIMES = '@@/actionTypes/gootTimes'
const beginGoodTimes = createAction(BEGIN_GOOD_TIMES);

(inner) createErrorAction(type, messageopt) → {errorActionCreator}

Given the specified type, and an optional custom error message, return a function that creates an object with a specified type, adds an error: true key to the top level, and assigns its arguments to a payload object

Parameters:
Name Type Attributes Description
type String

redux action type name

message String <optional>

a messge that describes the error, if none is given a generic message will be used

Source:
See:
  • tests

Returns:

Action creator function that applys a payload and returns an object of the given action type with the given payload

Type
errorActionCreator
Example
const BEGIN_GOOD_TIMES = '@@/actionTypes/gootTimes'
const beginGoodTimes = createAction(BEGIN_GOOD_TIMES);

(inner) createHandler(key) → {handlerFunction}

Given any string key name, returns a function that takes a state and action and returns a copy of the action's payload property renamed as the specified key

Parameters:
Name Type Description
key String

name of payloads state destination key

Source:
See:
  • tests

Returns:

A function that ignores current state and returns a copy of the action's payload property renamed as the specified key

Type
handlerFunction
Example
const testHandler = createHandler('bananas');
const state = {};
const action = { payload: { list: [1, 2, 3, 4] } }

testHandler(state, action)
//=> { bananas: [1, 2, 3, 4] }

(inner) errorActionCreator(payloadopt) → {Object}

Takes an optional payload and returns an object that describes an error redux action to be dispatched

Parameters:
Name Type Attributes Description
payload Object <optional>

payload data this action

Source:
Returns:

includes a type string, and optional payload and meta objects

Type
Object
Example
const payload = { soundTrack: 'Jurrasic Park' }
thisDidNotGoWell(payload)
//=> {
//  type: '@@/actionTypes/thisDidNotGoWell',
//  message: 'well something bad happened',
//  payload: { soundTrack: 'Jurrasic Park' },
//  error: true,
//}

(inner) getPayload(state, action) → {*}

Often a handler will have no need for the state value that is passed by convention as the first arg to a handler function, or any key on the action object other than payload. This function simply returns the payload key of the second arg that is passed to it.

Parameters:
Name Type Description
state Object

current state of app (always ignored)

action Object

the action being handled

Source:
Returns:

the payload key of action

Type
*
Example
const uppercasePayload = compose(toUpper, getPayload)

const action = { payload: 'i drink coffee please', type: 'COFFEE_ACTION' }
const state = { a: 1, b: 2, c: 3 }
uppercasePayload(state, action) //=> 'I DRINK COFFEE PLEASE'

(inner) handlerFunction(state, action) → {Object}

Function with a standard reducer signature of (state, action) and returns a renamed copy of the action's payload property

Parameters:
Name Type Description
state Object

current state

action Object

current action

Source:
Returns:

renamed action.payload

Type
Object

(inner) returnActionResult(actionType, payloadopt, metaopt) → {Object}

Takes a type, optional message, optional payload value, and an optional meta value and returns a standard redux action object descriptive of a redux action

Parameters:
Name Type Attributes Description
actionType String

type string for action

payload * <optional>

data relevant to error

meta * <optional>

data to describe the payload

Source:
Returns:

standard action object

Type
Object

(inner) returnErrorResult(actionType, messageopt, payloadopt, metaopt) → {Object}

Takes a type, optional message, optional payload value, and an optional meta value and returns a standard redux action object descriptive of a problem in execution

Parameters:
Name Type Attributes Description
actionType String

type string for action

message String <optional>

description of the error

payload * <optional>

data relevant to error

meta * <optional>

data to describe the payload

Source:
Returns:

standard action object

Type
Object