hyperflux 0.5.5
Install from the command line:
Learn more about npm packages
$ npm install @xrfoundation/hyperflux@0.5.5
Install via package.json:
"@xrfoundation/hyperflux": "0.5.5"
About this version
HyperFlux brings together various state management strategies in XREngine, in a way that makes it easy to introspect and test.
In XREngine, we define 3 different stores
The ENGINE store is non-networked, meaning actions are dispatched directly on the incoming queue, and run on the Engine timer.
createHyperStore({
name: 'ENGINE',
getDispatchId: () => 'engine',
getDispatchTime: () => Engine.instance.elapsedTime
})
// Engine timer callback:
const executeWorlds = (elapsedTime) => {
ActionFunctions.applyIncomingActions(Engine.instance.store)
// ...
}
The WORLD store is networked, meaning actions are dispatched directly on the outgoing queue, and run on the world's fixed tick.
createHyperStore({
name: 'WORLD',
networked: true,
getDispatchId: () => Engine.instance.userId,
getDispatchTime: () => this.fixedTick, // world.fixedTick
defaultDispatchDelay: 1
})
// IncomingActionSystem
import { applyIncomingActions } from '@xrengine/hyperflux'
export default async function IncomingActionSystem(world) {
return () => {
applyIncomingActions(world.store)
}
}
The CLIENT store is non-networked, and runs on a setInterval.
In any case, the appropriate store must be provided when dispatching an action:
dispatchAction(world.store, NetworkWorldAction.spawnAvatar({ parameters }))
Likewise when adding or removing receptors:
addActionReceptor(world.store, (a) =>
matches(a).when(NetworkWorldAction.spawnObject.matches, (a) => recepted.push(a))
)
State objects can also be defined and registered on a store:
const PeerState = defineState('peers', () => {
return [] // initial state
})
registerState(world.store, PeerState)
// get immutable state
const peerState = getState(world.store, PeerState)
// or, get mutable state (if and only if in a receptor function)
const mutablePeerState = getMutableState(world.store, PeerState)
All incoming, outoing, and historical actions accessible on the store.actions
object.