-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-crdt-extensions): 馃幐 setup ModelWithExt static class
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as clock from '../json-crdt-patch/clock'; | ||
import {NodeBuilder} from "../json-crdt-patch"; | ||
import {Extensions} from "../json-crdt/extensions/Extensions"; | ||
import {Model} from "../json-crdt/model"; | ||
import {SchemaToJsonNode} from "../json-crdt/schema/types"; | ||
import {CntExt} from './cnt'; | ||
import {MvalExt} from "./mval"; | ||
import {PeritextExt} from "./peritext"; | ||
|
||
const extensions = new Extensions(); | ||
|
||
extensions.register(CntExt); | ||
extensions.register(MvalExt); | ||
extensions.register(PeritextExt); | ||
|
||
export class ModelWithExt { | ||
public static readonly create = <S extends NodeBuilder>( | ||
schema?: S, | ||
sidOrClock: clock.ClockVector | number = Model.sid(), | ||
): Model<SchemaToJsonNode<S>> => { | ||
const model = Model.create(schema, sidOrClock); | ||
model.ext = extensions; | ||
return model; | ||
}; | ||
|
||
public static readonly load = <S extends NodeBuilder>( | ||
data: Uint8Array, | ||
sid?: number, | ||
schema?: S, | ||
): Model<SchemaToJsonNode<S>> => { | ||
const model = Model.load(data, sid, schema); | ||
model.ext = extensions; | ||
return model; | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/json-crdt-extensions/peritext/__tests__/extension.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {PeritextExt} from ".."; | ||
import {ModelWithExt} from "../../ModelWithExt"; | ||
|
||
test('..', () => { | ||
const model = ModelWithExt.create(); | ||
model.api.root({ | ||
text: PeritextExt.new('Hello, world\n'), | ||
}); | ||
|
||
console.log('' + model); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters