ObservableState
Extends:
Direct Subclass:
Example:
let name = new ObservableState("Foo");
name.getData(initial => console.log("Initial:", initial));
//> Initial: Foo
name.subscribe(data => {
console.log("Received:", data);
name.getState(currentState => assert(data === currentState))
});
name.emit("Foobar");
//> Received: Foobar
Constructor Summary
| Public Constructor | ||
| public |
constructor(initialState: Any) |
|
Method Summary
| Public Methods | ||
| public |
Same as Observable#emit, but sets
current state to |
|
| public |
filter(predicate: function(value: Any): boolean): ObservableState Same as Observable#filter, but returns ObservableState |
|
| public |
Return current state or asynchronously invoke callback |
|
| public |
map(mapper: function(value: Any): Any): ObservableState Same as Observable#map, but returns ObservableState |
|
| public |
Same as Observable#reduce, but starts with current state reduced |
|
Inherited Summary
| From class Observable | ||
| public |
Invoke each registered listener with |
|
| public |
filter(predicate: function(value: Any): boolean): Observable |
|
| public |
hasSubscribed(listener: function): boolean True if |
|
| public |
map(mapper: function(value: Any): Any): Observable |
|
| public |
|
|
| public |
subscribe(listener: function): Subscription Register listener |
|
| public |
unsubscribe(listener: function) Unregister listener |
|
Public Constructors
Public Methods
public emit(value: Any) source
Same as Observable#emit, but sets
current state to value before emitting
Override:
Observable#emitParams:
| Name | Type | Attribute | Description |
| value | Any | new state |
public filter(predicate: function(value: Any): boolean): ObservableState source
Same as Observable#filter, but returns ObservableState
Override:
Observable#filterpublic getState(callback: function): Any | undefined source
Return current state or asynchronously invoke callback
Params:
| Name | Type | Attribute | Description |
| callback | function |
|
Example:
let name = new ObservableState("Guest");
let val = name.getState();
assert(val === "Guest");
let name = new ObservableState("Guest");
let returnVal = name.getState(val => {
assert(val === "Guest")
});
assert(returnVal === undefined);
public map(mapper: function(value: Any): Any): ObservableState source
Same as Observable#map, but returns ObservableState
Override:
Observable#mappublic reduce(accumulator: Any, reducer: function(accumulator: Any, value: Any): Any): ObservableState source
Same as Observable#reduce, but starts with current state reduced