UNPKG

4 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17import { NamedNode, Node } from './snap/Node';
18import { ImmutableTree } from './util/ImmutableTree';
19import { Path } from './util/Path';
20/**
21 * This class holds a collection of writes that can be applied to nodes in unison. It abstracts away the logic with
22 * dealing with priority writes and multiple nested writes. At any given path there is only allowed to be one write
23 * modifying that path. Any write to an existing path or shadowing an existing path will modify that existing write
24 * to reflect the write added.
25 */
26export declare class CompoundWrite {
27 writeTree_: ImmutableTree<Node>;
28 constructor(writeTree_: ImmutableTree<Node>);
29 static empty(): CompoundWrite;
30}
31export declare function compoundWriteAddWrite(compoundWrite: CompoundWrite, path: Path, node: Node): CompoundWrite;
32export declare function compoundWriteAddWrites(compoundWrite: CompoundWrite, path: Path, updates: {
33 [name: string]: Node;
34}): CompoundWrite;
35/**
36 * Will remove a write at the given path and deeper paths. This will <em>not</em> modify a write at a higher
37 * location, which must be removed by calling this method with that path.
38 *
39 * @param compoundWrite - The CompoundWrite to remove.
40 * @param path - The path at which a write and all deeper writes should be removed
41 * @returns The new CompoundWrite with the removed path
42 */
43export declare function compoundWriteRemoveWrite(compoundWrite: CompoundWrite, path: Path): CompoundWrite;
44/**
45 * Returns whether this CompoundWrite will fully overwrite a node at a given location and can therefore be
46 * considered "complete".
47 *
48 * @param compoundWrite - The CompoundWrite to check.
49 * @param path - The path to check for
50 * @returns Whether there is a complete write at that path
51 */
52export declare function compoundWriteHasCompleteWrite(compoundWrite: CompoundWrite, path: Path): boolean;
53/**
54 * Returns a node for a path if and only if the node is a "complete" overwrite at that path. This will not aggregate
55 * writes from deeper paths, but will return child nodes from a more shallow path.
56 *
57 * @param compoundWrite - The CompoundWrite to get the node from.
58 * @param path - The path to get a complete write
59 * @returns The node if complete at that path, or null otherwise.
60 */
61export declare function compoundWriteGetCompleteNode(compoundWrite: CompoundWrite, path: Path): Node | null;
62/**
63 * Returns all children that are guaranteed to be a complete overwrite.
64 *
65 * @param compoundWrite - The CompoundWrite to get children from.
66 * @returns A list of all complete children.
67 */
68export declare function compoundWriteGetCompleteChildren(compoundWrite: CompoundWrite): NamedNode[];
69export declare function compoundWriteChildCompoundWrite(compoundWrite: CompoundWrite, path: Path): CompoundWrite;
70/**
71 * Returns true if this CompoundWrite is empty and therefore does not modify any nodes.
72 * @returns Whether this CompoundWrite is empty
73 */
74export declare function compoundWriteIsEmpty(compoundWrite: CompoundWrite): boolean;
75/**
76 * Applies this CompoundWrite to a node. The node is returned with all writes from this CompoundWrite applied to the
77 * node
78 * @param node - The node to apply this CompoundWrite to
79 * @returns The node with all writes applied
80 */
81export declare function compoundWriteApply(compoundWrite: CompoundWrite, node: Node): Node;