Quick Start
Install
Echo-D is available on NPM.
npm install echo-d
pnpm add echo-d
yarn add echo-d
Import
First things first, import Echo-D into your code.
import EchoD as EchoDHandler, { Node as EchoDNode Options as EchoDOptions, Context as EchoDContext, Storage as EchoDStorage,} from 'echo-d';
const { Handler: EchoDHandler, Node: EchoDNode, Options: EchoDOptions, Context: EchoDContext, Storage: EchoDStorage,} = require('echo-d');
Configure
Echo-D requires a few things to get started. Options are used to configure the behavior of Echo-D.
const customOptions = {}
const echoDOptions = new EchoDOptions(customOptions, EchoDNode.actions);
Context
Context is used to provide a context to Echo-D. Storage is used to provide a custom way to store state in Echo-D.
const customContext = {}
const echoDContext = new EchoDContext(customContext, echoDOptions, EchoDStorage);
Echo-D
Now that we have our options and context, we can create an instance of Echo-D.
const echoD = new EchoDHandler( echoDContext, echoDOptions,);
Using Echo-D to synchornize entity-component state to other Echo-D instances:
events.on('echoD', (messages) => { other_echoD.many(messages) // handle message(s) // Now our other Echo-D instance will have // an 'actor' with a 'position' of [0, 0, 0]});
Using Echo-D to create entity-component state:
// create pending stateechoD.spawnActor('actor') // spawn an actorechoD.upsertComponent('actor', 'position', [0, 0, 0]) // position actor
Using Echo-D to send updated entity-component state:
// send pending messages to other echoDsechoD.updater({ responder: (message) => { events.emit('echoD', message) // send message(s) },});