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.
- observable is an object or function with a
subscribe
method whose behavior conforms to this specification.
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);
- generator is a required argument.
- It must be an object.
- If generator is an object with a
next
method:- It must never be called after the
unsubscribe
method of subscription has been called. - It may optionally be passed a value.
- It may optionally return a value when called.
- If the method returns an object with a "done" property whose value is true, the generator should receive no further values.
- It must never be called after the
- If generator is an object with a
throw
method:- It must never be called after the
unsubscribe
method of subscription has been called. - 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.
- It may optionally return a value when called.
- If the method returns an object with a "done" property whose value is true, the generator should receive no further values.
- It must never be called after the
- If generator is an object with a
return
method:- It must never be called after the
unsubscribe
method of subscription has been called. - It should be called with a value designated as the return value.
- It must be called to indicate that the observable will send no further values.
- It should optionally return a value when called.
- If the method returns an object with a "done" property whose value is true, the generator should receive no further values.
- It must never be called after the
subscribe
must return a subscription object.- It must be an object with an
unsubscribe
method. - A call to the
unsubscribe
method should free all references to the generator held by the observable. - The
unsubscribe
method may be called multiple times. However, any subsequent calls after the first one should not have any side effects.
- It must be an object with an
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.