Git Product home page Git Product logo

observable-spec's Introduction

Observable

An open standard for sound, interoperable JavaScript Observables.

An Observable is an object that can send multiple values to a consumer. An Observable has a subscribe method which accepts a generator and can send it any number of values.

This specification details the behavior of the subscribe method, providing an interoperable base which all conformant Observable implementations must provide. As such, the specification should be considered very stable. Although the Observable organization may occasionally revise this specification with minor backward-compatible changes to address newly-discovered corner cases, we will integrate large or backward-incompatible changes only after careful consideration, discussion, and testing.

The core Observable specification does not deal with how to create Observables or Generators, choosing instead to focus on providing an interoperable subscribe method. Future work in companion specifications may touch on these subjects.

Terminology

  • observable is an object or function with a subscribe method whose behavior conforms to this specification.

Requirements

The subscribe Method

An observable must provide a subscribe method to allow consumers to receive its values. An observable's subscribe method accepts one argument and returns one value:

let subscription = observable.subscribe(generator);
  1. generator is a required argument.
    1. It must be an object.
  2. If generator is an object with a next method:
    1. It must never be called after the unsubscribe method of subscription has been called.
    2. It may optionally be passed a value.
    3. It may optionally return a value when called.
    4. If the method returns an object with a "done" property whose value is true, the generator should receive no further values.
  3. If generator is an object with a throw method:
    1. It must never be called after the unsubscribe method of subscription has been called.
    2. It must be called if an error is thrown anywhere in code either executed synchronously or asynchronously by observable. The error must be passed as the argument to the method.
    3. It may optionally return a value when called.
    4. If the method returns an object with a "done" property whose value is true, the generator should receive no further values.
  4. If generator is an object with a return method:
    1. It must never be called after the unsubscribe method of subscription has been called.
    2. It should be called with a value designated as the return value.
    3. It must be called to indicate that the observable will send no further values.
    4. It should optionally return a value when called.
    5. If the method returns an object with a "done" property whose value is true, the generator should receive no further values.
  5. subscribe must return a subscription object.
    1. It must be an object with an unsubscribe method.
    2. A call to the unsubscribe method should free all references to the generator held by the observable.
    3. The unsubscribe method may be called multiple times. However, any subsequent calls after the first one should not have any side effects.

CC0
To the extent possible under law, the Observable organization has waived all copyright and related or neighboring rights to Observable Specification. This work is published from: United States.

observable-spec's People

Contributors

jhusain avatar zenparsing avatar

Watchers

James Cloos avatar Gattamaneni Kumar Raja avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.