0.9.1 • Published 4 years ago

@redux-tools/namespaces v0.9.1

Weekly downloads
200
License
MIT
Repository
github
Last release
4 years ago

@redux-tools/namespaces

This package provides the main logic for associating Redux actions with a namespace.

API Reference

isActionFromNamespace

Function which checks if a Redux action is from a certain namespace. Returns false when both namespaces are defined and not equal, otherwise returns true.

There are essentially two edge cases:

  • If the action has no namespace, it is a global action and therefore affects all namespaces.
  • If the tested namespace is undefined, it is a global namespace and is therefore affected by all actions.
    • This allows easier usage of other packages (notably using namespacedConnect for dispatching actions affecting global reducers and epics, instead of having to use connect separately). Note that this behavior may be changed in the future versions.

Arguments

  1. action (Action): The Redux action to check. Should have a meta.namespace property.
  2. namespace (string): The namespace to check against.

Returns

(boolean): Whether the Redux action is from the specified namespace.

getNamespaceByAction

  • Returns the namespace of an action.

Arguments

  1. action (Action): The Redux action to get the namespace of. Should have a meta.namespace property.

Returns

(any): The value of the meta.namespace property.

attachNamespace

Associates an action with a namespace, overwriting any previous namespace.

Arguments

  1. namespace (string): The namespace to attach.
  2. action (Action): Action to attach the namespace to.

Returns

(Action): A new Redux action with a meta.namespace property.

defaultNamespace

Associates an action with a namespace unless it is already associated with some namespace.

Arguments

  1. namespace (string): The namespace to default to.
  2. action (Action): Action to default the namespace of.

Returns

(Action): A new Redux action with a meta.namespace property.