UNPKG

mutation-summary

Version:
70 lines (69 loc) 2.56 kB
import { IQuery } from "./IQuery"; import { IMutationSummaryOptions } from "./IMutationSummaryOptions"; import { Summary } from "./Summary"; import { IQueryValidator } from "./IQueryValidator"; /** * This is the main entry point class for the Mutation Summary library. When * created, a MutationSummary takes care of the details of observing the DOM * for changes, computing the "net-effect" of what's changed and then delivers * these changes to the provided callback. * * @example * ``` * * const ms = new MutationSummary({ * callback(summaries: Summary[]) { * summaries.forEach((summary: Summary) => console.log(summary)); * }, * queries: [ * { all: true } * ] * }); * ``` */ export declare class MutationSummary { static createQueryValidator: (root: Node, query: IQuery) => IQueryValidator; private _connected; private _options; private _observer; private readonly _observerOptions; private readonly _root; private readonly _callback; private readonly _elementFilter; private readonly _calcReordered; private _queryValidators; /** * Creates a new MutationSummary class using the specified options. * * @param opts The options that configure how the MutationSummary * instance will observe and report changes. */ constructor(opts: IMutationSummaryOptions); /** * Starts observation using an existing `MutationSummary` which has been * disconnected. Note that this function is just a convenience method for * creating a new `MutationSummary` with the same options. The next time * changes are reported, they will relative to the state of the observed * DOM at the point that `reconnect` was called. */ reconnect(): void; /** * Immediately calculates changes and returns them as an array of summaries. * If there are no changes to report, returns undefined. */ takeSummaries(): Summary[] | undefined; /** * Discontinues observation immediately. If DOM changes are pending delivery, * they will be fetched and reported as the same array of summaries which * are handed into the callback. If there is nothing to report, * this function returns undefined. * * @returns A list of changes that have not yet been delivered to a callback. */ disconnect(): Summary[] | undefined; private _observerCallback; private _createSummaries; private _checkpointQueryValidators; private _runQueryValidators; private _changesToReport; }