Skip to content

Commit

Permalink
feat(json-crdt): 🎸 issue demo
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jan 17, 2025
1 parent 874bced commit d022015
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/json-crdt/__demos__/issue-801.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* tslint:disable no-console */

/**
* Run this demo with:
*
* npx nodemon -q -x ts-node src/json-crdt/__demos__/issue-801.ts
*
* @see issue: https://github.com/streamich/json-joy/issues/801
*/

// Original source:
//
// interface SimpleObjectI {
// text: string
// }
// const SimpleObjectSchema = s.obj({
// text: s.con(''),
// })
// const model = Model.create().setSchema(SimpleObjectSchema)
// const root: SimpleObjectI = {
// text: 'foo'
// }
// model.api.root(root)
// type SimpleObjectNodeType = ObjNode<{
// text: ConNode<string>
// }>
// function foo(_node: ObjApi<SimpleObjectNodeType>) {}
// foo(model.api.node)


import {JsonNodeView, Model} from '..';
import {s} from '../../json-crdt-patch';
import {SchemaToJsonNode} from '../schema/types';

const SimpleObjectSchema = s.obj({
text: s.con<string>('foo'),
});

const model = Model.create(SimpleObjectSchema);

type SimpleObjectNodeType = SchemaToJsonNode<typeof SimpleObjectSchema>;
type SimpleObjectI = JsonNodeView<SimpleObjectNodeType>;
// type SimpleObjectI = ReturnType<(typeof model)['view']>;

console.log(model + '');

0 comments on commit d022015

Please sign in to comment.