js-base64#fromUint8Array TypeScript Examples
The following examples show how to use
js-base64#fromUint8Array.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: monaco-persistence.ts From netless-app with MIT License | 6 votes |
private setupYDocPersistence(): void {
const setAttrs = (): void => {
this.sideEffect.setTimeout(
() => {
const text = fromUint8Array(encodeStateAsUpdate(this.doc));
if (text !== this.textAttr) {
// @TODO handle large text
this.context.updateAttributes(["text"], text);
}
},
1000,
"setAttrs"
);
};
this.sideEffect.add(() => {
const onDocDestroyed = (): void => {
this.isDocDestroyed = true;
};
this.doc.on("destroy", onDocDestroyed);
return () => this.doc.off("destroy", onDocDestroyed);
});
this.sideEffect.add(() => {
const onDocUpdated = (_update: Uint8Array, origin: string): void => {
// Only the one who updates the yDoc (origin is yMonaco) writes to the shared App Attributes
if (!this.isDocDestroyed && origin !== "_remote_edit_") {
setAttrs();
}
};
this.doc.on("update", onDocUpdated);
return () => this.doc.off("update", onDocUpdated);
});
}
Example #2
Source File: y-monaco.ts From netless-app with MIT License | 6 votes |
private setupDocUpdate(): void {
const displayer = this.context.getDisplayer();
this.sideEffect.add(() => {
const handleUpdate = (event: WhiteEvent) => {
this.authorId = String(event.authorId);
if (event.authorId !== displayer.observerId) {
try {
applyUpdate(this.doc, toUint8Array(event.payload), "_remote_edit_");
} catch (e) {
console.warn(e);
}
}
};
displayer.addMagixEventListener(this.MagixMonacoDocChannel, handleUpdate);
return () => displayer.removeMagixEventListener(this.MagixMonacoDocChannel, handleUpdate);
});
this.sideEffect.add(() => {
const handleUpdate = (update: Uint8Array, origin: unknown) => {
if (origin !== "_remote_edit_" && this.context.getIsWritable()) {
const room = this.context.getRoom();
if (room) {
this.authorId = String(displayer.observerId);
room.dispatchMagixEvent(this.MagixMonacoDocChannel, fromUint8Array(update));
}
}
};
this.doc.on("update", handleUpdate);
return () => this.doc.off("update", handleUpdate);
});
}