MutationStream
Observe dom mutation using a MutationObserver as a stream (AsyncIterator)
Constructor Summary
Public Constructor | ||
public |
Construct a new MutationStream |
Method Summary
Public Methods | ||
public |
[Symbol.asyncIterator](): AsyncIterator<?MutationRecord[]> |
|
public |
Disconnects the mutation observer and ends the stream |
|
public |
Start observing an element for mutations |
|
public |
observeStream(elem: Node, config: Object): AsyncIterableIterator<MutationRecord[]> Start observing an element for mutations and receive an async iterator yielding the observed mutations |
|
public |
async * predicateStreamItr(startPredicate: function(): boolean, stopPredicate: function(): boolean): AsyncIterator<?MutationRecord[]> Returns an mutation stream that ends if the startPredicate returns false otherwise keeps the stream alive until disconnect or the stopPredicate, polled at 1.5 second intervals when waiting for next mutation, returns false. |
|
public |
predicatedStream(elem: Node, config: Object, startPredicate: function(): boolean, stopPredicate: function(): boolean): AsyncIterator<MutationRecord[]> Creates a conditional mutation stream. |
|
public |
async * streamItr(): AsyncIterator<MutationRecord[]> Returns an stream (async iterator) that yields the observed mutations. |
Private Methods | ||
private |
Returns a promise that resolves with the next observed mutation |
Public Constructors
Public Methods
public [Symbol.asyncIterator](): AsyncIterator<?MutationRecord[]> source
Return:
AsyncIterator<?MutationRecord[]> |
public observeStream(elem: Node, config: Object): AsyncIterableIterator<MutationRecord[]> source
Start observing an element for mutations and receive an async iterator yielding the observed mutations
Return:
AsyncIterableIterator<MutationRecord[]> |
public async * predicateStreamItr(startPredicate: function(): boolean, stopPredicate: function(): boolean): AsyncIterator<?MutationRecord[]> source
Returns an mutation stream that ends if the startPredicate returns false otherwise keeps the stream alive until disconnect or the stopPredicate, polled at 1.5 second intervals when waiting for next mutation, returns false. Automatically disconnects at the end.
Params:
Name | Type | Attribute | Description |
startPredicate | function(): boolean | Predicate function right before mutations are yielded to determine if the stream should end immediately or not |
|
stopPredicate | function(): boolean | Predicate function polled while waiting for mutations to occur that returns false to indicate the stream should end. |
Return:
AsyncIterator<?MutationRecord[]> |
public predicatedStream(elem: Node, config: Object, startPredicate: function(): boolean, stopPredicate: function(): boolean): AsyncIterator<MutationRecord[]> source
Creates a conditional mutation stream. If the startPredicate does not return true then the the observer discontents ending the stream. Otherwise the stream continues to emit mutations until the observer is disconnected or the stopPredicate returns true. The stopPredicate is polled at 1.5 second intervals when the observer is waiting for the next mutation.
Params:
Name | Type | Attribute | Description |
elem | Node | The element to be observed for mutations |
|
config | Object | Configuration object accepted by mutation observers |
|
startPredicate | function(): boolean | Predicate function right before mutations are yielded to determine if the stream should end immediately or not |
|
stopPredicate | function(): boolean | Predicate function polled while waiting for mutations to occur that returns false to indicate the stream should end. |
Return:
AsyncIterator<MutationRecord[]> |
public async * streamItr(): AsyncIterator<MutationRecord[]> source
Returns an stream (async iterator) that yields the observed mutations. Must have called observe before calling this method, otherwise no mutations will be yielded
Return:
AsyncIterator<MutationRecord[]> |