diff options
author | tschicke-brown <tyler_schicke@brown.edu> | 2019-05-09 19:25:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-09 19:25:58 -0400 |
commit | 6691c55623fff5194b5fd1a830096e3925281301 (patch) | |
tree | 2458827f32530528e306821db8fd37ced27ba7ef /src/new_fields/CursorField.ts | |
parent | 39fd912fd4cd33f30a943290295a59992b9868eb (diff) | |
parent | e98dd0bf2ec4354daf95cc0d104cab1193fd4160 (diff) |
Merge pull request #128 from browngraphicslab/cursor_refactor
Cursor refactor
Diffstat (limited to 'src/new_fields/CursorField.ts')
-rw-r--r-- | src/new_fields/CursorField.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/new_fields/CursorField.ts b/src/new_fields/CursorField.ts new file mode 100644 index 000000000..7fd326a5f --- /dev/null +++ b/src/new_fields/CursorField.ts @@ -0,0 +1,55 @@ +import { ObjectField, Copy, OnUpdate } from "./ObjectField"; +import { observable } from "mobx"; +import { Deserializable } from "../client/util/SerializationHelper"; +import { serializable, createSimpleSchema, object } from "serializr"; + +export type CursorPosition = { + x: number, + y: number +} + +export type CursorMetadata = { + id: string, + identifier: string +} + +export type CursorData = { + metadata: CursorMetadata, + position: CursorPosition +} + +const PositionSchema = createSimpleSchema({ + x: true, + y: true +}); + +const MetadataSchema = createSimpleSchema({ + id: true, + identifier: true +}); + +const CursorSchema = createSimpleSchema({ + metadata: object(MetadataSchema), + position: object(PositionSchema) +}); + +@Deserializable("cursor") +export default class CursorField extends ObjectField { + + @serializable(object(CursorSchema)) + readonly data: CursorData; + + constructor(data: CursorData) { + super(); + this.data = data; + } + + setPosition(position: CursorPosition) { + this.data.position = position; + this[OnUpdate](); + } + + [Copy]() { + return new CursorField(this.data); + } +}
\ No newline at end of file |