Skip to content

Headless usage? #43

@Blakeinstein

Description

@Blakeinstein

Implementation should ideally been straightforward. As I could simply have made a client adapter that modifies an internal string.

class HeadlessAdapter implements IEditorAdapter {
    protected _content: string;

    constructor() {
        this._content = "";
    }
    on(): void {
        return;
    }
    off(): void {
        return;
    }
    registerUndo(): void {
        return;
    }
    registerRedo(): void {
        return;
    }
    deregisterUndo(): void {
        return;
    }
    deregisterRedo(): void {
        return;
    }
    getCursor(): ICursor | null {
        return null;
    }
    setCursor(): void {
        return;
    }
    setOtherCursor(): IDisposable {
        return {
            dispose: () => {
                return;
            },
        };
    }
    getText(): string {
        return this._content;
    }
    setText(text: string): void {
        this._content = text;
    }
    setInitiated(): void {
        return;
    }
    applyOperation(operation: IPlainTextOperation): void {
        if (!operation.isNoop()) {
            return;
        }
        this._content = operation.apply(this._content);
    }
    invertOperation(operation: IPlainTextOperation): IPlainTextOperation {
        return operation.invert(this._content);
    }
    dispose(): void {
        return;
    }

}

const headlessAdapter = new HeadlessAdapter();
const firebaseAdapter = new FirebaseAdapter(dbRef, 0, "#000000", "Admin");
const opts = <IFirepadConstructorOptions> {
	userId: 0,
	userColor: "#000000",
	userName: "Admin"
};

const firepad = new Firepad(firebaseAdapter, headlessAdapter, opts);

Unfortunately this errors out with the following

ReferenceError: self is not defined
    at Object.call (/workspace/template-typescript-node/node_modules/@hackerrank/firepad/dist/webpack:/node_modules/@operational-transformation/plaintext-editor/lib/index.js:1:515)
    at require (/workspace/template-typescript-node/node_modules/@hackerrank/firepad/dist/webpack:/webpack/bootstrap:19:32)
    at /workspace/template-typescript-node/node_modules/@hackerrank/firepad/dist/webpack:/lib/firepad-classic.js:3:26
    at /workspace/template-typescript-node/node_modules/@hackerrank/firepad/dist/firepad.min.js:1:69312

Looks like its bundled with webpack, and the global object is set to self.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions