Library for strongly typed asynchronous programming


License
MIT
Install
npm install typescene-async@1.1.7

Documentation

Typescene Async Library

Library for strongly typed asynchronous programming, part of the Typescene toolkit.

Note: To learn more about Typescene, head over to the main Typescene repository.

Typescene Async Library - API Reference

Purpose of this module

This library provides a toolkit for asynchronous programming, primarily for the browser (or other browser-based front end, such as Electron). It has been created to support the development of the Typescene GUI toolkit.

This module exports generic classes and functions that implement common patterns for asynchronous programming, such as promises, signals, and observables.

Overview

The included functions and classes build on one another, in the following order:

  • defer function --- provides a basic queueing mechanism to schedule code asynchronously.
  • Signals --- defined using defineSignal, which creates a class that derives from Signal, of which instances can be emitted along with a single value. Like events, but different.
  • Promises --- the Promise class provides a Promises/A+ compliant promise implementation, along with some additional convenience methods.
  • Observable values --- these are objects wrapped around a single value (in the .value property of an ObservableValue object), which can be subscribed to for capturing changes to this value. In addition, observables can be defined using a getter function, which may use other observable values in turn (making changes cascade asynchronously down a dependency tree when subscribed to; this can be employed to implement composite UIs efficiently).
  • Observable arrays --- arrays of observable values, hiding the ObservableValue instances in getters and setters for all array indices of an ObservableArray object.
  • Observable objects --- loosely defined objects for which some or all of the properties are made observable (using getters and setters) as properties of an ObservableObject, which also defines a PropertyChange signal to listen for changes without having to subscribe to observable values directly.
  • Injection --- this mechanism can be used to inject default (observable) values into a property on all instances of a class.

Refer to the samples for common usage patterns.