@xrengine/hyperflux

1.1.3 • Public • Published

HyperFlux

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, meaning actions are dispatched directly on the incoming queue, and run on the Engine timer.

createHyperStore({
  name: 'ENGINE',
  getDispatchId: () => 'engine',
  getDispatchTime: () => Engine.instance.elapsedTime
})
// IncomingActionSystem
import { applyIncomingActions } from '@xrengine/hyperflux'
export default async function IncomingActionSystem(world) {
  return () => {
    applyIncomingActions(Engine.instance.store)
  }
}

In any case, the appropriate store must be provided when dispatching an action:

dispatchAction( WorldNetworkAction.spawnAvatar({ parameters }))

Likewise when adding or removing receptors:

addActionReceptor((a) =>
  matches(a).when(WorldNetworkAction.spawnObject.matches, (a) => recepted.push(a))
)

State objects can also be defined and retrieved from a store:

const PeerState = defineState('peers', () => {
    return [] // initial state
})

// get state
const peerState = getState(Engine.instance.store, PeerState)

All incoming, outoing, and historical actions accessible on the store.actions object.

Readme

Keywords

none

Package Sidebar

Install

npm i @xrengine/hyperflux

Weekly Downloads

0

Version

1.1.3

License

MIT

Unpacked Size

52.9 kB

Total Files

15

Last publish

Collaborators

  • mrhegemon
  • hexafield
  • barankyle
  • speigg