Home Reference Source

Function

Static Public Summary
public

BindHandlers(args: ...*): *

Creates a decorator for binding action handlers to a store.

public

bindActions(args: ...*): *

Decorates a store with any number of viewAction definitions.

public

bindCalls(args: ...*): *

Decorates a store with any number of call definitions.

public

bindHandlers(actions: *, handlers: ...*): *

Decorates a store with any number of action handlers.

public

callFactory(name: *, objectPattern1: {"namespace": *, "defaultActions": *, "actions": *, "logger": *}): {"name": *, "actions": *, "create": *, "createActions": *}

public

callSeries(calls: array, options: object): promise

Retuns a promise and executes a series of calls.

public

connect(definitions: Array<{store: AltStore, props: Array<string>}>): *

A component decorator for connecting to immutable stores.

public

connectAlternative(store: *, mapStateToProps: *, WrappedComponent: *): *

public

createActions(namespace: string, actions: array<string>): object

Creates simple (data-pass-through) actions with a namespace.

public

createLogger(name: *): {"log": *, "info": *, "warn": *, "error": *, "trace": *}

public

createStore(displayName: *, objectPattern1: {"alt": *, "state": *, "calls": *, "sources": *, "viewActions": *}): *

public
public
public

flatten(args: ...*): *

Reduces a mixed array to a flat one.

public
public

getLevel(): *

public

getSources(calls: *): *

public
public

handlerFactory(action: *, objectPattern1: {"namespace": *, "logger": *}): {"create": *}

public
public

setAltInstance(alt: *)

public

setLevel(value: *)

public

validateCreator(call: *, logger: *): *

public

validateDefinition(definition: *, logger: *): *

public

validateHandler(handler: *, logger: *): *

Static Public

public BindHandlers(args: ...*): * source

import BindHandlers from '@xailabs/altx/src/BindHandlers.js'

Creates a decorator for binding action handlers to a store. A binding is created for each action that has a matching handler method mapping.

The decorator takes any number of action handler definitions as arguments and applies their bindings after concatinating them to a flat list, so you can pass either of these:

  • an array of handler definitions
  • any number of array of handler definitions
  • any number of handlerdefinitions without arrays
  • any mixed variation

See manual/usage/action-handlers.md for more on this topic.

Params:

NameTypeAttributeDescription
args ...*

Return:

*

public bindActions(args: ...*): * source

Decorates a store with any number of viewAction definitions.

Params:

NameTypeAttributeDescription
args ...*

Return:

*

public bindCalls(args: ...*): * source

Decorates a store with any number of call definitions.

Params:

NameTypeAttributeDescription
args ...*

Return:

*

public bindHandlers(actions: *, handlers: ...*): * source

Decorates a store with any number of action handlers.

Params:

NameTypeAttributeDescription
actions *
handlers ...*

Return:

*

public callFactory(name: *, objectPattern1: {"namespace": *, "defaultActions": *, "actions": *, "logger": *}): {"name": *, "actions": *, "create": *, "createActions": *} source

import callFactory from '@xailabs/altx/src/callFactory.js'

Params:

NameTypeAttributeDescription
name *
objectPattern1 {"namespace": *, "defaultActions": *, "actions": *, "logger": *}
  • optional
  • default: {}

Return:

{"name": *, "actions": *, "create": *, "createActions": *}

public callSeries(calls: array, options: object): promise source

import callSeries from '@xailabs/altx/src/callSeries.js'

Retuns a promise and executes a series of calls. Uses a timeout initially so that we don't run into errors when still in the middle of a dispatch.

import {callSeries} from 'shared/flux';

Params:

NameTypeAttributeDescription
calls array

An array of function that each returns a promise

options object

An array of function that each returns a promise

options.log boolean

Whether to log individual calls

Return:

promise

A promise that will be resolved when all calls succeeded or rejected if one call failed

public connect(definitions: Array<{store: AltStore, props: Array<string>}>): * source

A component decorator for connecting to immutable stores.

Basically a wrapper around alt/utils/connectToStores.
Adds the necessary static methods getStores() and getPropsFromStores() to the decorated component.

  • Supports multiple stores.
  • Supports a simplified, string-based access to stores, with optional renaming of props.
  • Supports more flexible, redux-like access to stores using mapper functions.

String notation

Params:

NameTypeAttributeDescription
definitions Array<{store: AltStore, props: Array<string>}>

A list of objects that each define a store connection

Return:

*

Example:

@connect([{store: MyStore, props: ['myValue', 'anotherValue']}])
export default class MyComponent extends React.Component {
     render() {
         const {myValue, anotherValue} = this.props;
         ...
     }
}

You can rename props using the ` as ` alias syntax
@connect([{
     store: PeopleStore,
     props: ['items as people']
}, {
     store: ProductStore,
     props: ['items as products']
}])
export default class MyComponent extends React.Component {
     render() {
         // this.props.people, this.props.products, ...
     }
}

### Function notation

Use mapper functions instead of strings in order to manually retrieve store values.
The function receives the store state and the component props.
@connect([{
     store: MyStore,
     props: (state, props) => {
         return {
             item: state.get('items').filter(item => item.get('id') === props.id)
         }
     }
}])
export default class MyComponent extends React.Component {
     render() {
         const item = this.props.item;
     }
}

Technically, you could also mix all access methods, but this defeats the purpose of simple access:
@connect([{
     store: MyStore,
     props: ['someProp', 'anotherProp', (state, props) => {
         return {
             item: state.get('items').filter(item => item.get('id') === props.id)
         }
     }, 'some.nested.value as foo']
}])
export default class MyComponent extends React.Component {
     ...
}

There are however valid usecase for mixing access methods. For example, you might have keys that themselves contain dots.
For example, that is the case when using `validate.js` with nested constraints and keeping validation results in the store.
There might be an `errors` map in your storewith keys like `user.address.street`. In such a case you wouldn't be able to access those values because the dots do not
represent the actual keyPath in the tree:
@connect([{
  store,
  props: ['user.address.street', (state) => ({errors: state.getIn(['errors', 'user.address.street'])})]
}])

See:

public connectAlternative(store: *, mapStateToProps: *, WrappedComponent: *): * source

import {connectAlternative} from '@xailabs/altx/src/decorators/connect.js'

Params:

NameTypeAttributeDescription
store *
mapStateToProps *
WrappedComponent *

Return:

*

public createActions(namespace: string, actions: array<string>): object source

import createActions from '@xailabs/altx/src/createActions.js'

Creates simple (data-pass-through) actions with a namespace. Basically just like alt.generateActions, but within a given namespace instead of 'global'.

Params:

NameTypeAttributeDescription
namespace string

The namespace to use for the actions

actions array<string>

An array of action names

Return:

object

An object containing the generated actions and constants

public createLogger(name: *): {"log": *, "info": *, "warn": *, "error": *, "trace": *} source

import {createLogger} from '@xailabs/altx/src/utils/logging.js'

Params:

NameTypeAttributeDescription
name *

Return:

{"log": *, "info": *, "warn": *, "error": *, "trace": *}

public createStore(displayName: *, objectPattern1: {"alt": *, "state": *, "calls": *, "sources": *, "viewActions": *}): * source

import createStore from '@xailabs/altx/src/createStore.js'

Params:

NameTypeAttributeDescription
displayName *
objectPattern1 {"alt": *, "state": *, "calls": *, "sources": *, "viewActions": *}
  • optional
  • default: {}

Return:

*

public creatorConstraints() source

import {creatorConstraints} from '@xailabs/altx/src/utils/validate/validateCreator.js'

public definitionConstraints() source

import {definitionConstraints} from '@xailabs/altx/src/utils/validate/validateDefinition.js'

public flatten(args: ...*): * source

Reduces a mixed array to a flat one.

Params:

NameTypeAttributeDescription
args ...*

Return:

*

public getAltInstance(): * source

import {getAltInstance} from '@xailabs/altx/src/altInstance.js'

Return:

*

public getLevel(): * source

import {getLevel} from '@xailabs/altx/src/utils/logging.js'

Return:

*

public getSources(calls: *): * source

import getSources from '@xailabs/altx/src/getSources.js'

Params:

NameTypeAttributeDescription
calls *

Return:

*

public handlerConstraints() source

import {handlerConstraints} from '@xailabs/altx/src/utils/validate/validateHandler.js'

public handlerFactory(action: *, objectPattern1: {"namespace": *, "logger": *}): {"create": *} source

import handlerFactory from '@xailabs/altx/src/handlerFactory.js'

Params:

NameTypeAttributeDescription
action *
objectPattern1 {"namespace": *, "logger": *}
  • optional
  • default: {}

Return:

{"create": *}

public resetStores() source

import {resetStores} from '@xailabs/altx/src/ImmutableStore.js'

public setAltInstance(alt: *) source

import {setAltInstance} from '@xailabs/altx/src/altInstance.js'

Params:

NameTypeAttributeDescription
alt *

public setLevel(value: *) source

import {setLevel} from '@xailabs/altx/src/utils/logging.js'

Params:

NameTypeAttributeDescription
value *

public validateCreator(call: *, logger: *): * source

Params:

NameTypeAttributeDescription
call *
logger *
  • optional

Return:

*

public validateDefinition(definition: *, logger: *): * source

Params:

NameTypeAttributeDescription
definition *
logger *
  • optional

Return:

*

public validateHandler(handler: *, logger: *): * source

Params:

NameTypeAttributeDescription
handler *
logger *
  • optional

Return:

*