Skip to content

Bug: Constructor shouldn't call async function #58

Description

@sondreb

The constructor performs a call to an async function and assigns the callback handler to the array, which is suppose to be populated with the "op" object and not the callback function itself.

generateOperation is an async method, but it's called in constructor (which can't be async):

  constructor(options = { }) {
    this.#ops = options.ops || [ ];
    this.#generateKeyPair = options.generateKeyPair || generateKeyPair;
    if (!this.#ops.length) {
      this.#ops.push(this.generateOperation('create', options.content || { }, false));
    }
  }

Since it's a callback reference and not the actual operation data, the previous field on second operation becomes a ZoneAwarePromise instead of the operation data.

previous: ZoneAwarePromise

This results in serialization of the state not being correct.

This can probably only be solved by removing this default create operation and requiring the library consumer to call some "create" method instead.

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