Skip to content

Commit 369b2b3

Browse files
committed
feat(json-crdt-extensions): 🎸 improve Peritext model schema definitions
1 parent 08386ba commit 369b2b3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/json-crdt-extensions/peritext/Peritext.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ import type {SliceSchema, SliceType} from './slice/types';
2323
import type {SchemaToJsonNode} from '../../json-crdt/schema/types';
2424
import type {AbstractRga} from '../../json-crdt/nodes/rga';
2525
import type {ChunkSlice} from './util/ChunkSlice';
26+
import type {Stateful} from './types';
2627

2728
const EXTRA_SLICES_SCHEMA = s.vec(s.arr<SliceSchema>([]));
29+
const LOCAL_DATA_SCHEMA = EXTRA_SLICES_SCHEMA;
2830

29-
type SlicesModel = Model<SchemaToJsonNode<typeof EXTRA_SLICES_SCHEMA>>;
31+
export type ExtraSlicesModel = Model<SchemaToJsonNode<typeof EXTRA_SLICES_SCHEMA>>;
32+
export type LocalModel = Model<SchemaToJsonNode<typeof LOCAL_DATA_SCHEMA>>;
3033

3134
/**
3235
* Context for a Peritext instance. Contains all the data and methods needed to
3336
* interact with the text.
3437
*/
35-
export class Peritext<T = string> implements Printable {
38+
export class Peritext<T = string> implements Printable, Stateful {
3639
/**
3740
* *Slices* are rich-text annotations that appear in the text. The "saved"
3841
* slices are the ones that are persisted in the document.
@@ -76,8 +79,8 @@ export class Peritext<T = string> implements Printable {
7679
public readonly str: AbstractRga<T>,
7780
slices: ArrNode,
7881
// TODO: Add test that verifies that SIDs are different across all three models.
79-
extraSlicesModel: SlicesModel = Model.create(EXTRA_SLICES_SCHEMA, model.clock.sid - 1),
80-
localSlicesModel: SlicesModel = Model.create(EXTRA_SLICES_SCHEMA, SESSION.LOCAL),
82+
extraSlicesModel: ExtraSlicesModel = Model.create(EXTRA_SLICES_SCHEMA, model.clock.sid - 1),
83+
localSlicesModel: LocalModel = Model.create(LOCAL_DATA_SCHEMA, SESSION.LOCAL),
8184
) {
8285
this.savedSlices = new Slices(this, slices);
8386
this.extraSlices = new ExtraSlices(this, extraSlicesModel.root.node().get(0)!);
@@ -327,7 +330,7 @@ export class Peritext<T = string> implements Printable {
327330
api.apply();
328331
}
329332

330-
// ---------------------------------------------------------------- Printable
333+
/** ----------------------------------------------------- {@link Printable} */
331334

332335
public toString(tab: string = ''): string {
333336
const nl = () => '';
@@ -348,7 +351,7 @@ export class Peritext<T = string> implements Printable {
348351
);
349352
}
350353

351-
// ----------------------------------------------------------------- Stateful
354+
/** ------------------------------------------------------ {@link Stateful} */
352355

353356
public hash: number = 0;
354357

0 commit comments

Comments
 (0)