Home Reference Source
import {MutationStream} from 'lib/mutations.js'
public class | source

MutationStream

Observe dom mutation using a MutationObserver as a stream (AsyncIterator)

Constructor Summary

Public Constructor
public

Construct a new MutationStream

Member Summary

Public Members
public

mo: MutationObserver

Private Members
private
private

_resolve: function(arg: *): *

Method Summary

Public Methods
public

[Symbol.asyncIterator](): AsyncIterator<?MutationRecord[]>

public

Disconnects the mutation observer and ends the stream

public

observe(elem: Node, config: Object)

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

_getNext(): Promise<?MutationRecord[]>

Returns a promise that resolves with the next observed mutation

Public Constructors

public constructor() source

Construct a new MutationStream

Public Members

public mo: MutationObserver source

Private Members

private _loopStream: boolean source

private _resolve: function(arg: *): * source

Public Methods

public [Symbol.asyncIterator](): AsyncIterator<?MutationRecord[]> source

Return:

AsyncIterator<?MutationRecord[]>

public disconnect() source

Disconnects the mutation observer and ends the stream

public observe(elem: Node, config: Object) source

Start observing an element for mutations

Params:

NameTypeAttributeDescription
elem Node

The element to be observed for mutations

config Object

Configuration object accepted by mutation observers

public observeStream(elem: Node, config: Object): AsyncIterableIterator<MutationRecord[]> source

Start observing an element for mutations and receive an async iterator yielding the observed mutations

Params:

NameTypeAttributeDescription
elem Node

The element to be observed for mutations

config Object

Configuration object accepted by mutation observers

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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[]>

Private Methods

private _getNext(): Promise<?MutationRecord[]> source

Returns a promise that resolves with the next observed mutation

Return:

Promise<?MutationRecord[]>