API
import * as Mycelial from '@mycelial/core';
const spore = Mycelial.create(namespace, key)
Creates a new spore(composition of CRDTs).
namespace
(string) creates a namespace that acts as a topic when publishing changes.key
(number) a unique replica id
spore.events.addEventListener(event, handler)
Creates event handlers, providing reactivity to changes.
event
('update' | 'apply') specifies which type of event to listen to. 'update' events occur after appending values locally, 'apply' events occur when remote changes are synchronized.
spore.commit([[string, string, string | number | boolean]])
Appends new records to the spore.
spore.commit([
{
$id: 100,
name: 'James M.',
phone: '5555555555',
email: '[email protected]',
},
]);
Websocket API
import * as Websocket from '@mycelial/websocket';
const spore = Mycelial.create('contacts', 123);
const ws = Websocket.create(spore, {
endpoint: 'wss://v0alpha-relay.fly.dev/v0alpha',
});
Websocket.create(spore, endpoint)
Creates a websocket adapter that synchronizes the replica across two or more nodes
License
Apache 2.0