-
Notifications
You must be signed in to change notification settings - Fork 440
/
invalidate-path-sets-as-json-values.js
107 lines (86 loc) · 2.93 KB
/
invalidate-path-sets-as-json-values.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module.exports = invalidate_path_sets_as_json_values;
var clone = require("falcor/support/clone-dense-json");
var array_clone = require("falcor/support/array-clone");
var array_slice = require("falcor/support/array-slice");
var options = require("falcor/support/options");
var walk_path_set = require("falcor/walk/walk-path-set");
var is_object = require("falcor/support/is-object");
var get_valid_key = require("falcor/support/get-valid-key");
var update_graph = require("falcor/support/update-graph");
var invalidate_node = require("falcor/support/invalidate-node");
var collect = require("falcor/lru/collect");
var positions = require("falcor/support/positions");
var _cache = positions.cache;
var _message = positions.message;
var _jsong = positions.jsong;
var _json = positions.json;
function invalidate_path_sets_as_json_values(model, pathsets, onNext) {
var roots = options([], model);
var index = -1;
var count = pathsets.length;
var nodes = roots.nodes;
var parents = array_clone(nodes);
var requested = [];
var optimized = [];
roots[_cache] = roots.root;
roots.onNext = onNext;
while (++index < count) {
var pathset = pathsets[index];
walk_path_set(onNode, onEdge, pathset, 0, roots, parents, nodes, requested, optimized);
}
collect(
roots.lru,
roots.expired,
roots.version,
roots.root.$size || 0,
model._maxSize,
model._collectRatio
);
return {
values: null,
errors: roots.errors,
requestedPaths: roots.requestedPaths,
optimizedPaths: roots.optimizedPaths,
requestedMissingPaths: roots.requestedMissingPaths,
optimizedMissingPaths: roots.optimizedMissingPaths
};
}
function onNode(pathset, roots, parents, nodes, requested, optimized, is_reference, is_branch, key, keyset, is_keyset) {
var parent;
if (key == null) {
if ((key = get_valid_key(optimized)) == null) {
return;
}
parent = parents[_cache];
} else {
parent = nodes[_cache];
}
var node = parent[key];
if (is_reference) {
parents[_cache] = parent;
nodes[_cache] = node;
return;
}
if (is_branch) {
parents[_cache] = nodes[_cache] = node;
return;
}
nodes[_cache] = node;
var lru = roots.lru;
var size = node.$size || 0;
var version = roots.version;
invalidate_node(parent, node, key, roots.lru);
update_graph(parent, size, version, lru);
}
function onEdge(pathset, depth, roots, parents, nodes, requested, optimized, key, keyset) {
var node = nodes[_cache];
var type = is_object(node) && node.$type || undefined;
var onNext = roots.onNext;
if (Boolean(type) && onNext) {
onNext({
path: array_clone(requested),
value: clone(roots, node, type, node && node.value)
});
}
roots.requestedPaths.push(array_slice(requested, roots.offset));
}