Example Setup
This example is split into two parts, the ./host.js and the ./client.js.
However it is possible to use Echo-D in other network topologies.
It is important to prevent the flow of data from the various nodes to not cycle
around or else it will create an infinite loop.
To prevent this, it is recommended to use the mask option in the updater method
as well as the other options in the EchoD constructor.
Events
Uses EventEmitter from node:events to create an events object.
This can be bundled for use in browsers with a bundler such as
esbuild, webpack, bun build, or another bundler.
import { EventEmitter } from 'node:events';export const events = new EventEmitter( );Here is an example of barebones events implementation.
It is recommended to use a library such as mitt for handling events.
However this illustrates that Echo-D only uses on and emit methods.
export const events = { evo: { }, on( ev, cb ) { if ( Array.isArray( this.evo[ ev ] ) ) this.evo[ ev ].push( cb ); else this.evo[ ev ] = [ cb ]; }, emit( ev, ...data ) { if ( Array.isArray( this.evo[ ev ] ) ) for ( const cb of this.evo[ ev ] ) cb.call( this, ...data ); }};