|
1
|
|
|
"use strict"; |
|
2
|
|
|
var __assign = (this && this.__assign) || function () { |
|
3
|
|
|
__assign = Object.assign || function(t) { |
|
4
|
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) { |
|
5
|
|
|
s = arguments[i]; |
|
6
|
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) |
|
|
|
|
|
|
7
|
|
|
t[p] = s[p]; |
|
|
|
|
|
|
8
|
|
|
} |
|
9
|
|
|
return t; |
|
10
|
|
|
}; |
|
11
|
|
|
return __assign.apply(this, arguments); |
|
12
|
|
|
}; |
|
13
|
|
|
var __spreadArrays = (this && this.__spreadArrays) || function () { |
|
14
|
|
|
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; |
|
|
|
|
|
|
15
|
|
|
for (var r = Array(s), k = 0, i = 0; i < il; i++) |
|
|
|
|
|
|
16
|
|
|
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) |
|
|
|
|
|
|
17
|
|
|
r[k] = a[j]; |
|
|
|
|
|
|
18
|
|
|
return r; |
|
19
|
|
|
}; |
|
20
|
|
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
21
|
|
|
var monocle_ts_1 = require("monocle-ts"); |
|
22
|
|
|
var ArrayC_1 = require("./io/ArrayC"); |
|
23
|
|
|
var RelationshipsCacheC_1 = require("./io/RelationshipsCacheC"); |
|
24
|
|
|
var RelationshipsRecord_1 = require("./RelationshipsRecord"); |
|
25
|
|
|
var ResourceIdentifier_1 = require("./ResourceIdentifier"); |
|
26
|
|
|
var fromRelationships = function (x) { |
|
27
|
|
|
return RelationshipsCacheC_1.RelationshipsCacheC.is(x) |
|
28
|
|
|
? x |
|
29
|
|
|
: [0, {}, x]; |
|
30
|
|
|
}; |
|
31
|
|
|
var lenses = { |
|
32
|
|
|
counter: new monocle_ts_1.Lens(function (s) { return s[0]; }, function (a) { return function (s) { return ([a, s[1], s[2]]); }; }), |
|
33
|
|
|
global: new monocle_ts_1.Lens(function (s) { return s[1]; }, function (a) { return function (s) { return ([s[0], a, s[2]]); }; }), |
|
34
|
|
|
local: new monocle_ts_1.Lens(function (s) { return s[2]; }, function (a) { return function (s) { return ([s[0], s[1], a]); }; }) |
|
35
|
|
|
}; |
|
36
|
|
|
var monoid = { |
|
37
|
|
|
empty: [0, {}, {}], |
|
38
|
|
|
concat: function (x, y) { |
|
39
|
|
|
var _a = [x, y].map(fromRelationships), xs = _a[0], ys = _a[1]; |
|
40
|
|
|
var locals = Object.values(lenses.local.get(ys)) |
|
41
|
|
|
.reduce(function (array, item) { return (__spreadArrays(array, (ArrayC_1.ArrayC().is(item) ? item : [item]))); }, []); |
|
42
|
|
|
return [ |
|
43
|
|
|
lenses.counter.get(xs) + (lenses.counter.get(ys) || locals.length), |
|
44
|
|
|
__assign(__assign(__assign({}, lenses.global.get(xs)), lenses.global.get(ys)), locals.reduce(function (record, identifier) { |
|
45
|
|
|
var _a; |
|
46
|
|
|
return (__assign(__assign({}, record), (_a = {}, _a[ResourceIdentifier_1.ResourceIdentifier.iso.string.get(identifier)] = identifier, _a))); |
|
|
|
|
|
|
47
|
|
|
}, {})), |
|
48
|
|
|
__assign(__assign({}, lenses.local.get(xs)), lenses.local.get(ys)) |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
}; |
|
52
|
|
|
exports.RelationshipsCache = { |
|
53
|
|
|
fromRelationships: fromRelationships, |
|
54
|
|
|
emptyLocal: function (cache) { |
|
55
|
|
|
return lenses.local.set({})(fromRelationships(cache)); |
|
56
|
|
|
}, |
|
57
|
|
|
nestLocal: function (cache, key) { |
|
58
|
|
|
return (function (cache) { |
|
59
|
|
|
return lenses.local.set(RelationshipsRecord_1.RelationshipsRecord.nest(lenses.local.get(cache), key))(cache); |
|
60
|
|
|
})(fromRelationships(cache)); |
|
61
|
|
|
}, |
|
62
|
|
|
lens: lenses, |
|
63
|
|
|
monoid: { |
|
64
|
|
|
self: monoid |
|
65
|
|
|
} |
|
66
|
|
|
}; |
|
67
|
|
|
|
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.