1
+ import { Path } from "../util/path" ;
2
+ import { Index } from "./indexes/Index" ;
3
+
1
4
/**
2
5
* Node is an interface defining the common functionality for nodes in
3
6
* a DataSnapshot.
4
7
*
5
8
* @interface
6
9
*/
7
- export const Node = function ( ) { } ;
8
-
9
-
10
- /**
11
- * Whether this node is a leaf node.
12
- * @return {boolean } Whether this is a leaf node.
13
- */
14
- Node . prototype . isLeafNode ;
15
-
16
-
17
- /**
18
- * Gets the priority of the node.
19
- * @return {!Node } The priority of the node.
20
- */
21
- Node . prototype . getPriority ;
10
+ export interface Node {
11
+ /**
12
+ * Whether this node is a leaf node.
13
+ * @return {boolean } Whether this is a leaf node.
14
+ */
15
+ isLeafNode ( ) : boolean ;
22
16
23
17
24
- /**
25
- * Returns a duplicate node with the new priority.
26
- * @param {!Node } newPriorityNode New priority to set for the node.
27
- * @return {!Node } Node with new priority.
28
- */
29
- Node . prototype . updatePriority ;
18
+ /**
19
+ * Gets the priority of the node.
20
+ * @return {!Node } The priority of the node.
21
+ */
22
+ getPriority ( ) : Node ;
30
23
31
24
32
- /**
33
- * Returns the specified immediate child, or null if it doesn't exist .
34
- * @param {string } childName The name of the child to retrieve .
35
- * @return {!Node } The retrieved child, or an empty node .
36
- */
37
- Node . prototype . getImmediateChild ;
25
+ /**
26
+ * Returns a duplicate node with the new priority .
27
+ * @param {!Node } newPriorityNode New priority to set for the node .
28
+ * @return {!Node } Node with new priority .
29
+ */
30
+ updatePriority ( newPriorityNode : Node ) : Node ;
38
31
39
32
40
- /**
41
- * Returns a child by path , or null if it doesn't exist.
42
- * @param {!fb.core.util.Path } path The path of the child to retrieve.
43
- * @return {!Node } The retrieved child or an empty node.
44
- */
45
- Node . prototype . getChild ;
33
+ /**
34
+ * Returns the specified immediate child , or null if it doesn't exist.
35
+ * @param {string } childName The name of the child to retrieve.
36
+ * @return {!Node } The retrieved child, or an empty node.
37
+ */
38
+ getImmediateChild ( childName : string ) : Node ;
46
39
47
40
48
- /**
49
- * Returns the name of the child immediately prior to the specified childNode, or null.
50
- * @param {!string } childName The name of the child to find the predecessor of.
51
- * @param {!Node } childNode The node to find the predecessor of.
52
- * @param {!fb.core.snap.Index } index The index to use to determine the predecessor
53
- * @return {?string } The name of the predecessor child, or null if childNode is the first child.
54
- */
55
- Node . prototype . getPredecessorChildName ;
41
+ /**
42
+ * Returns a child by path, or null if it doesn't exist.
43
+ * @param {!Path } path The path of the child to retrieve.
44
+ * @return {!Node } The retrieved child or an empty node.
45
+ */
46
+ getChild ( path : Path ) : Node ;
56
47
57
- /**
58
- * Returns a duplicate node, with the specified immediate child updated.
59
- * Any value in the node will be removed.
60
- * @param {string } childName The name of the child to update.
61
- * @param {!Node } newChildNode The new child node
62
- * @return {!Node } The updated node.
63
- */
64
- Node . prototype . updateImmediateChild ;
65
48
49
+ /**
50
+ * Returns the name of the child immediately prior to the specified childNode, or null.
51
+ * @param {!string } childName The name of the child to find the predecessor of.
52
+ * @param {!Node } childNode The node to find the predecessor of.
53
+ * @param {!Index } index The index to use to determine the predecessor
54
+ * @return {?string } The name of the predecessor child, or null if childNode is the first child.
55
+ */
56
+ getPredecessorChildName ( childName : String , childNode : Node , index : Index ) : string ;
66
57
67
- /**
68
- * Returns a duplicate node, with the specified child updated. Any value will
69
- * be removed.
70
- * @param {!fb.core.util.Path } path The path of the child to update.
71
- * @param {!Node } newChildNode The new child node, which may be an empty node
72
- * @return {!Node } The updated node.
73
- */
74
- Node . prototype . updateChild ;
58
+ /**
59
+ * Returns a duplicate node, with the specified immediate child updated.
60
+ * Any value in the node will be removed.
61
+ * @param {string } childName The name of the child to update.
62
+ * @param {!Node } newChildNode The new child node
63
+ * @return {!Node } The updated node.
64
+ */
65
+ updateImmediateChild ( childName : string , newChildNode : Node ) : Node ;
75
66
76
- /**
77
- * True if the immediate child specified exists
78
- * @param {!string } childName
79
- * @return {boolean }
80
- */
81
- Node . prototype . hasChild ;
82
67
83
- /**
84
- * @return {boolean } True if this node has no value or children.
85
- */
86
- Node . prototype . isEmpty ;
68
+ /**
69
+ * Returns a duplicate node, with the specified child updated. Any value will
70
+ * be removed.
71
+ * @param {!Path } path The path of the child to update.
72
+ * @param {!Node } newChildNode The new child node, which may be an empty node
73
+ * @return {!Node } The updated node.
74
+ */
75
+ updateChild ( path : Path , newChildNode : Node ) : Node ;
87
76
77
+ /**
78
+ * True if the immediate child specified exists
79
+ * @param {!string } childName
80
+ * @return {boolean }
81
+ */
82
+ hasChild ( childName : string ) : boolean ;
88
83
89
- /**
90
- * @return {number } The number of children of this node .
91
- */
92
- Node . prototype . numChildren ;
84
+ /**
85
+ * @return {boolean } True if this node has no value or children .
86
+ */
87
+ isEmpty ( ) : boolean ;
93
88
94
89
95
- /**
96
- * Calls action for each child.
97
- * @param {!fb.core.snap.Index } index
98
- * @param {function(string, !Node) } action Action to be called for
99
- * each child. It's passed the child name and the child node.
100
- * @return {* } The first truthy value return by action, or the last falsey one
101
- */
102
- Node . prototype . forEachChild ;
90
+ /**
91
+ * @return {number } The number of children of this node.
92
+ */
93
+ numChildren ( ) : number ;
103
94
104
95
105
- /**
106
- * @param {boolean= } opt_exportFormat True for export format (also wire protocol format).
107
- * @return {* } Value of this node as JSON.
108
- */
109
- Node . prototype . val ;
96
+ /**
97
+ * Calls action for each child.
98
+ * @param {!Index } index
99
+ * @param {function(string, !Node) } action Action to be called for
100
+ * each child. It's passed the child name and the child node.
101
+ * @return {* } The first truthy value return by action, or the last falsey one
102
+ */
103
+ forEachChild ( index : Index , action : ( string , node ) => any ) : any ;
110
104
105
+ /**
106
+ * @param {boolean= } opt_exportFormat True for export format (also wire protocol format).
107
+ * @return {* } Value of this node as JSON.
108
+ */
109
+ val ( exportFormat ?: boolean ) : Object ;
111
110
112
- /**
113
- * @return {string } hash representing the node contents.
114
- */
115
- Node . prototype . hash ;
111
+ /**
112
+ * @return {string } hash representing the node contents.
113
+ */
114
+ hash ( ) : string ;
116
115
117
- /**
118
- * @param {!Node } other Another node
119
- * @return {!number } -1 for less than, 0 for equal, 1 for greater than other
120
- */
121
- Node . prototype . compareTo ;
116
+ /**
117
+ * @param {!Node } other Another node
118
+ * @return {!number } -1 for less than, 0 for equal, 1 for greater than other
119
+ */
120
+ compareTo ( other : Node ) : number ;
122
121
123
- /**
124
- * @param {!Node } other
125
- * @return {boolean } Whether or not this snapshot equals other
126
- */
127
- Node . prototype . equals ;
122
+ /**
123
+ * @param {!Node } other
124
+ * @return {boolean } Whether or not this snapshot equals other
125
+ */
126
+ equals ( other : Node ) : boolean ;
128
127
129
- /**
130
- * @param {!fb.core.snap. Index } indexDefinition
131
- * @return {!Node } This node, with the specified index now available
132
- */
133
- Node . prototype . withIndex ;
128
+ /**
129
+ * @param {!Index } indexDefinition
130
+ * @return {!Node } This node, with the specified index now available
131
+ */
132
+ withIndex ( indexDefinition : Index ) : Node ;
134
133
135
- /**
136
- * @param {!fb.core.snap.Index } indexDefinition
137
- * @return {boolean }
138
- */
139
- Node . prototype . isIndexed ;
134
+ /**
135
+ * @param {!Index } indexDefinition
136
+ * @return {boolean }
137
+ */
138
+ isIndexed ( indexDefinition : Index ) : boolean ;
139
+ }
140
140
141
141
/**
142
142
*
@@ -146,8 +146,7 @@ Node.prototype.isIndexed;
146
146
* @struct
147
147
*/
148
148
export class NamedNode {
149
- name ;
150
- node ;
149
+ constructor ( public name : string , public node : Node ) { }
151
150
152
151
/**
153
152
*
@@ -158,10 +157,5 @@ export class NamedNode {
158
157
static Wrap ( name : string , node : Node ) {
159
158
return new NamedNode ( name , node ) ;
160
159
}
161
-
162
- constructor ( name , node ) {
163
- this . name = name ;
164
- this . node = node ;
165
- }
166
160
}
167
161
0 commit comments