Class

FluxState

@psionic/flux.FluxState(config)

Class representing a state whose value can be set, read, and used as a dependency within the Flux framework.

New FluxStates should be created with the createFluxState function -- NOT with a new FluxState() constructor. Otherwise, the Flux object will not be instantiated in the general FluxManager singleton, and functionality may break.

Constructor

# new FluxState(config)

Parameters:
Name Type Description
config Object

The configuration object

id string

The ID to use for the FluxState; should be unique among all other active Flux objects

value *

The initial value to set as data; this will be recursively cloned so that any changes to this value (if it is an object) will not affect the FluxState instance's value

View Source flux/src/flux-state/flux-state.js, line 22

Methods

# get() → {*}

Gets a deeply-cloned copy of the current data from the FluxState.

View Source flux/src/flux-state/flux-state.js, line 85

A deeply-cloned copy of the current data from the FluxState.

*
Example
// Create a FluxState object
const profileState = createFluxState({
     id: 'profileState',
     value: { name: 'John' },
});

// Read the FluxState object's current value
const profile = profileState.get(); // { name: 'John' }

# getID() → {string}

Get the Flux object's ID.

View Source flux/src/flux-state/flux-state.js, line 124

The Flux object's ID

string

# set(newValue)

Sets the new value for the FluxState.

Parameters:
Name Type Description
newValue *

The new value to store in the FluxState

View Source flux/src/flux-state/flux-state.js, line 108

Example
// Create a FluxState object
const profileState = createFluxState({
     id: 'profileState',
     value: null,
});

// Set the FluxState object's new value
profileState.set({ name: 'John' });

// The FluxState will now hold the new value
const profile = profileState.get(); // { name: 'John' }