Interface Reader<T>

The reader is responsible for combining multiple Readables and scheduling a callback to be invoked when one or more of the Readables have changed. Choose one of the appropriate methods; Reader.once or Reader.subscribe that suits the needs of the Mod. An instance of the reader is created by calling the Mod.createReader method.

interface Reader<T> {
    hasExpired(): Promise<boolean>;
    hasValueChanged(value: T[number], ...values: T[number][]): boolean;
    once(callback: ((...values: T) => void), onReadError?: ((error: string) => void)): ReaderSubscription;
    subscribe(callback: ((...values: T) => void), onReadError?: ((error: string) => void)): ReaderSubscription;
}

Type Parameters

  • T extends ReadonlyArray<any>

Methods

  • Checks if any of the readables have a new value available. If this function returns true, the callback in the current subscription, or a new call to Reader.once is guaranteed to be invoked. The intended use of this method is to cancel rendering of the Mod if there are new values to any of the readables specified when the reader was created.

    Returns Promise<boolean>

  • Check whether one or more passed arguments are new since the last time the subscribe loop was called.

    Parameters

    • value: T[number]

      Value from subscribe or once arguments.

    • Rest...values: T[number][]

      Additional values from subscribe or once arguments.

    Returns boolean

    true if any of the values are new, otherwise false.

    Check if the data view has changed in the subscribe loop.

    let reader = mod.createReader(mod.visualization.data(), mod.windowSize());
    reader.subscribe((dataView, size) => {
    console.log(reader.hasValueChanged(dataView));
    });

    1.3

  • Read the content once for the readables specified when the reader was created. Any current subscription for this reader will be cancelled.

    Parameters

    • callback: ((...values: T) => void)

      The callback function that is called once when there is at least one new value to read.

        • (...values): void
        • Parameters

          • Rest...values: T

          Returns void

    • OptionalonReadError: ((error: string) => void)

      Optional callback function that will be called if there are errors reading the readables.

        • (error): void
        • Parameters

          • error: string

          Returns void

    Returns ReaderSubscription

    Read content of a mod property once.

    let reader = mod.createReader(mod.property("CreatedBy"));
    reader.once((createdBy) => {
    console.log(await createdBy.value());
    });
  • Subscribe to changes in the content for the specified readables when the reader was created.

    Parameters

    • callback: ((...values: T) => void)

      The callback function that is called every time when there is at least one new value to read. The callback function will not be called until the previous callback function has returned.

        • (...values): void
        • Parameters

          • Rest...values: T

          Returns void

    • OptionalonReadError: ((error: string) => void)

      Optional callback function that will be called if there are errors reading the readables.

        • (error): void
        • Parameters

          • error: string

          Returns void

    Returns ReaderSubscription

    Subscribe to changes in the DataView.

    let reader = mod.createReader(mod.visualization.data());
    reader.subscribe((dataView) => {
    console.log(await dataView.rowCount());
    });