diff options
Diffstat (limited to 'src/client/DocServer.ts')
-rw-r--r-- | src/client/DocServer.ts | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 652a9b701..b7b03f04c 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -7,11 +7,14 @@ import { RefField } from '../new_fields/RefField'; import { Id, HandleUpdate } from '../new_fields/FieldSymbols'; export namespace DocServer { - const _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {}; + let _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {}; const _socket = OpenSocket(`${window.location.protocol}//${window.location.hostname}:4321`); const GUID: string = Utils.GenerateGuid(); + let _isReadOnly = false; export function makeReadOnly() { + if (_isReadOnly) return; + _isReadOnly = true; _CreateField = field => { _cache[field[Id]] = field; }; @@ -19,6 +22,16 @@ export namespace DocServer { _respondToUpdate = emptyFunction; } + export function makeEditable() { + if (!_isReadOnly) return; + location.reload(); + // _isReadOnly = false; + // _CreateField = _CreateFieldImpl; + // _UpdateField = _UpdateFieldImpl; + // _respondToUpdate = _respondToUpdateImpl; + // _cache = {}; + } + export function prepend(extension: string): string { return window.location.origin + extension; } @@ -27,6 +40,14 @@ export namespace DocServer { Utils.Emit(_socket, MessageStore.DeleteAll, {}); } + export function DeleteDocument(id: string) { + Utils.Emit(_socket, MessageStore.DeleteField, id); + } + + export function DeleteDocuments(ids: string[]) { + Utils.Emit(_socket, MessageStore.DeleteFields, ids); + } + export async function GetRefField(id: string): Promise<Opt<RefField>> { let cached = _cache[id]; if (cached === undefined) { @@ -97,29 +118,33 @@ export namespace DocServer { return map; } - let _UpdateField = (id: string, diff: any) => { + function _UpdateFieldImpl(id: string, diff: any) { if (id === updatingId) { return; } Utils.Emit(_socket, MessageStore.UpdateField, { id, diff }); - }; + } + + let _UpdateField = _UpdateFieldImpl; export function UpdateField(id: string, diff: any) { _UpdateField(id, diff); } - let _CreateField = (field: RefField) => { + function _CreateFieldImpl(field: RefField) { _cache[field[Id]] = field; const initialState = SerializationHelper.Serialize(field); Utils.Emit(_socket, MessageStore.CreateField, initialState); - }; + } + + let _CreateField = _CreateFieldImpl; export function CreateField(field: RefField) { _CreateField(field); } let updatingId: string | undefined; - let _respondToUpdate = (diff: any) => { + function _respondToUpdateImpl(diff: any) { const id = diff.id; if (id === undefined) { return; @@ -141,7 +166,10 @@ export namespace DocServer { } else { update(field); } - }; + } + + let _respondToUpdate = _respondToUpdateImpl; + function respondToUpdate(diff: any) { _respondToUpdate(diff); } |