Skip to content

Quick Start

Install

Echo-D is available on NPM.

Terminal window
npm install echo-d

Import

First things first, import Echo-D into your code.

echo-d.js
import EchoD as EchoDHandler, {
Node as EchoDNode
Options as EchoDOptions,
Context as EchoDContext,
Storage as EchoDStorage,
} from 'echo-d';

Configure

Echo-D requires a few things to get started. Options are used to configure the behavior of Echo-D.

echo-d.js
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.

echo-d.js
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.

echo-d.js
const echoD = new EchoDHandler(
echoDContext,
echoDOptions,
);

Using Echo-D to synchornize entity-component state to other Echo-D instances:

echo.js
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:

echo.js
// create pending state
echoD.spawnActor('actor') // spawn an actor
echoD.upsertComponent('actor', 'position', [0, 0, 0]) // position actor

Using Echo-D to send updated entity-component state:

echo.js
// send pending messages to other echoDs
echoD.updater({
responder: (message) => {
events.emit('echoD', message) // send message(s)
},
});