Skip to content

Commit

Permalink
feat(json-crdt-extensions): 🎸 allow passing in extra slice and local …
Browse files Browse the repository at this point in the history
…slice models
  • Loading branch information
streamich committed May 2, 2024
1 parent ce6eb34 commit b10d1cf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/json-crdt-extensions/peritext/Peritext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {SESSION} from '../../json-crdt-patch/constants';
import {s} from '../../json-crdt-patch';
import type {ITimestampStruct} from '../../json-crdt-patch/clock';
import type {Printable} from 'tree-dump/lib/types';
import type {SliceType} from './types';
import type {MarkerSlice} from './slice/MarkerSlice';
import type {SliceSchema, SliceType} from './slice/types';

const EXTRA_SLICES_SCHEMA = s.vec(s.arr<SliceSchema>([]));

/**
* Context for a Peritext instance. Contains all the data and methods needed to
Expand Down Expand Up @@ -50,18 +52,18 @@ export class Peritext implements Printable {
public readonly model: Model,
public readonly str: StrNode,
slices: ArrNode,
extraSlicesModel = Model.create(EXTRA_SLICES_SCHEMA, model.clock.sid - 1),
localSlicesModel = Model.create(EXTRA_SLICES_SCHEMA, SESSION.LOCAL),
) {
this.savedSlices = new Slices(this.model, slices, this.str);

const extraModel = Model.create(s.vec(s.arr([])), this.model.clock.sid - 1);
this.extraSlices = new Slices(extraModel, extraModel.root.node().get(0)!, this.str);
this.extraSlices = new Slices(extraSlicesModel, extraSlicesModel.root.node().get(0)!, this.str);

const localModel = Model.create(s.vec(s.arr([])), SESSION.LOCAL);
const localApi = localModel.api;
const localApi = localSlicesModel.api;
localApi.onLocalChange.listen(() => {
localApi.flush();
});
this.localSlices = new LocalSlices(localModel, localModel.root.node().get(0)!, this.str);
this.localSlices = new LocalSlices(localSlicesModel, localSlicesModel.root.node().get(0)!, this.str);

this.editor = new Editor(this, this.localSlices);
}
Expand Down

0 comments on commit b10d1cf

Please sign in to comment.