Principle:AFK surf Open agent Doc Collection Creation
| Knowledge Sources | |
|---|---|
| Domains | Editor, CRDT_Sync, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Pattern of assembling a CRDT-backed document collection from a registered block schema, an id generator, and pluggable doc/blob/awareness sources.
Description
A DocCollection (Workspace) is the root container for a set of yjs documents in BlockSuite. Constructing one requires: a Schema holding the legal block flavors (AffineSchemas); an id generator (nanoid for production, auto-increment for deterministic E2E tests); doc sources that sync the yjs state (e.g. BroadcastChannelDocSource for local collaboration); blob sources that store binary assets (MemoryBlobSource with optional IndexedDBBlobSource/MockServerBlobSource shadows); and awareness sources that track presence (BroadcastChannelAwarenessSource). Store-scoped extensions are attached before the collection is started so the DI container is consistent from the first mutation. A Transformer is typically co-constructed for import/export and debugging.
Usage
Apply this principle whenever you need a live, syncable, schema-validated document tree — embedding the BlockSuite editor in an app, building a collaborative canvas, or scaffolding a test workspace. The source choice determines the persistence and collaboration topology.
Theoretical Basis
The collection is a multi-document yjs host. Each doc is a CRDT; sources are the transport/storage adapters that move CRDT updates and blobs between peers and storage. The schema constrains the block-flavour domain so that mutations stay legal.
Pseudo-code:
const schema = new Schema();
schema.register(AffineSchemas);
const options: DocCollectionOptions = {
id, idGenerator,
awarenessSources: [new BroadcastChannelAwarenessSource(id)],
docSources: { main: new BroadcastChannelDocSource(room) },
blobSources: { main: new MemoryBlobSource(), shadows: [] },
};
const collection = new TestWorkspace(options);
collection.storeExtensions = manager.get('store');
collection.start();