Edit

Observable Class

Caution

This class is still in pre-release. Its signature may change or it may be removed in future releases.

A class that represents data that can be Observed. Extensively used for UI.

Methods

getData

getData(): T

Gets the data from the Observable.

Returns T

getFilteredText

getFilteredText(this: Observable<T & string>, player: minecraftserver.Player): Promise<string | TextFilteringError[]>

Gets filtered data from the Observable (only available for strings). In case of failure, it will return an array of TextFilteringError that can provide more context about the filtering process. For testing purposes, the options are available under "Creator -> Text Filtering" settings menu. This delay is only applied to the getFilteredText function and can be used to simulate network latency when testing.

Parameters

  • this: Observable<T & string>
  • player: minecraftserver.Player

Returns Promise<string | TextFilteringError[]>

setData

setData(data: T): void

Sets the data on this Observable and notifies the subscribers.

Parameters

  • data: T

Returns void

subscribe

subscribe(listener: (arg0: T) => void): (arg0: T) => void

Subscribes a callback to any changes that occur to the Observable. The return value can be passed into the unsubscribe function to stop listening to changes.

Parameters

  • listener: (arg0: T) => void

Returns (arg0: T) => void

toJSON

toJSON(): unknown

Returns unknown

unsubscribe

unsubscribe(listener: (arg0: T) => void): void

Unsubscribe a callback from any changes that occur to the Observable. This takes the return value from the subscribe function.

Parameters

  • listener: (arg0: T) => void

Returns void

create

static create(data: T, options?: ObservableOptions): Observable<T>

Creates an Observable, use this instead of a constructor.

Parameters

  • data: T
  • options?: ObservableOptions

Returns Observable<T>