Live collaboration with Yjs over ActionCable
All editors now work on a server document at the same time instead of taking turns behind an edit lock. - The document's content is a sequence of Yjs updates (document_updates); DocumentChannel stores and relays them immediately, checks access on subscribe and again whenever links or memberships change. - app/frontend/collab/: the store stays position-based; a binding maps it to a Yjs form with stable row/column ids, so a row inserted by one person doesn't misplace what another is typing. Remote changes are applied only after pending local ones went into Yjs. - Per-person undo (Y.UndoManager), presence via awareness: the others' selections as coloured boxes with names, avatars in the toolbar. - Existing JSON documents convert on first open, deterministically, so two people opening one at once end up with the same Yjs state. - Editors compact the stored updates after 200 and keep a JSON snapshot current for export and duplicating. Edit lock and polling are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# Live collaboration (Yjs): a document's content is the sum of its Yjs
|
||||
# updates. `documents.content` stays as a JSON snapshot (duplicate, export,
|
||||
# the first conversion to Yjs). The edit lock and version counter go.
|
||||
class LiveCollaboration < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :document_updates do |t|
|
||||
t.references :document, type: :uuid, null: false, foreign_key: { on_delete: :cascade }
|
||||
t.references :user, foreign_key: { on_delete: :nullify }
|
||||
t.binary :data, null: false
|
||||
t.datetime :created_at, null: false
|
||||
end
|
||||
|
||||
remove_column :documents, :version, :integer, null: false, default: 1
|
||||
remove_column :documents, :lock_holder, :string
|
||||
remove_column :documents, :lock_holder_name, :string
|
||||
remove_column :documents, :lock_expires_at, :datetime
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user