Template for a library exporting a custom Collabs CRDT.
This template demonstrates how to define a custom Collab (collaborative data structure / CRDT) and export it for reuse.
See src/custom_type.ts.
test/custom_type.test.ts lets you test your Collab using TestingRuntimes.
The rest of this template is a (basic) TypeScript library setup.
Many types can be built out of existing Collabs types using CObject
. However, sometimes you need the power of raw message passing, e.g., when writing a CPrimitive
.
Collabs expects Uint8Array | string
for these messages. Some suggested ways to encoded and decode:
- Use JSON to encode plain JS objects as strings.
- Use BSON (binary JSON) to encode plain JS objects as
Uint8Array
s. - Use provided Serializer instances - in particular, DefaultSerializer, which can serialize many non-circular types, including CollabID.
- Use protobuf.js with its Typescript support. This is what Collabs does. See the @collabs/collabs package for an example of how to set this up; it's a bit tricky to get the ESM build working and make it tree-shakable, due to bugs in the library's ESM output (as of 09/2021).