@rbxts/covenant 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/covenant.d.ts +7 -7
- package/src/covenant.luau +39 -33
- package/src/hooks.luau +168 -77
package/package.json
CHANGED
package/src/covenant.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Covenant {
|
|
|
16
16
|
private systems;
|
|
17
17
|
private worldChangesForReplication;
|
|
18
18
|
private worldChangesForPrediction;
|
|
19
|
-
private
|
|
19
|
+
private undefinedStringifiedComponents;
|
|
20
20
|
private replicatedStringifiedComponents;
|
|
21
21
|
private predictedStringifiedComponents;
|
|
22
22
|
private started;
|
|
@@ -41,16 +41,16 @@ export declare class Covenant {
|
|
|
41
41
|
subscribeComponent<T>(component: Entity<T>, subscriber: (entity: Entity, state: T | undefined, previousState: T | undefined) => void): () => void;
|
|
42
42
|
private worldDelete;
|
|
43
43
|
worldComponent<T extends defined>(): Entity<T>;
|
|
44
|
-
private
|
|
44
|
+
private checkComponentDefined;
|
|
45
45
|
private defineComponentNetworkBehavior;
|
|
46
|
-
|
|
46
|
+
defineComputedComponent<T extends defined>({ component, queriedComponents, recipe, replicated, predictionValidator, }: {
|
|
47
47
|
replicated: boolean;
|
|
48
48
|
predictionValidator: ComponentPredictionValidator | false;
|
|
49
49
|
component: Entity<T>;
|
|
50
50
|
queriedComponents: Entity[][];
|
|
51
51
|
recipe: (entity: Entity, lastState: T | undefined, updateId: number, hooks: CovenantHooks) => T | undefined;
|
|
52
52
|
}): void;
|
|
53
|
-
|
|
53
|
+
defineManagedChildren<T extends defined>({ parentComponent, parentEntityTrackerComponent, childIdentityComponent, getIdentifier, queriedComponents, recipe, replicated, predictionValidator, }: {
|
|
54
54
|
replicated: boolean;
|
|
55
55
|
predictionValidator: ComponentPredictionValidator | false;
|
|
56
56
|
parentComponent: Entity<ReadonlyArray<T>>;
|
|
@@ -60,12 +60,12 @@ export declare class Covenant {
|
|
|
60
60
|
queriedComponents: Entity[][];
|
|
61
61
|
recipe: (entity: Entity, lastChildrenStates: ReadonlyArray<T>, updateId: number, hooks: CovenantHooks) => ReadonlyArray<T>;
|
|
62
62
|
}): void;
|
|
63
|
-
|
|
63
|
+
defineEntitySource<T extends defined>({ identityComponent, recipe, replicated, }: {
|
|
64
64
|
replicated: boolean;
|
|
65
65
|
identityComponent: Entity<T>;
|
|
66
66
|
recipe: (updateId: number, hooks: CovenantHooks) => {
|
|
67
|
-
statesToCreate
|
|
68
|
-
entitiesToDelete
|
|
67
|
+
statesToCreate?: ReadonlyArray<T>;
|
|
68
|
+
entitiesToDelete?: ReadonlyArray<Entity>;
|
|
69
69
|
};
|
|
70
70
|
}): void;
|
|
71
71
|
private worldEntity;
|
package/src/covenant.luau
CHANGED
|
@@ -48,7 +48,7 @@ do
|
|
|
48
48
|
self.systems = {}
|
|
49
49
|
self.worldChangesForReplication = {}
|
|
50
50
|
self.worldChangesForPrediction = {}
|
|
51
|
-
self.
|
|
51
|
+
self.undefinedStringifiedComponents = {}
|
|
52
52
|
self.replicatedStringifiedComponents = {}
|
|
53
53
|
self.predictedStringifiedComponents = {}
|
|
54
54
|
self.started = false
|
|
@@ -235,14 +235,14 @@ do
|
|
|
235
235
|
function Covenant:start()
|
|
236
236
|
local _arg0 = not self.started
|
|
237
237
|
assert(_arg0, "Already started")
|
|
238
|
-
local _exp = next(self.
|
|
238
|
+
local _exp = next(self.undefinedStringifiedComponents) == nil
|
|
239
239
|
-- ▼ ReadonlySet.size ▼
|
|
240
240
|
local _size = 0
|
|
241
|
-
for _ in self.
|
|
241
|
+
for _ in self.undefinedStringifiedComponents do
|
|
242
242
|
_size += 1
|
|
243
243
|
end
|
|
244
244
|
-- ▲ ReadonlySet.size ▲
|
|
245
|
-
local _arg1 = `There are {_size} components that are not
|
|
245
|
+
local _arg1 = `There are {_size} components that are not defined`
|
|
246
246
|
assert(_exp, _arg1)
|
|
247
247
|
self.started = true
|
|
248
248
|
local _exp_1 = self.systems
|
|
@@ -439,15 +439,15 @@ do
|
|
|
439
439
|
local c = self._world:component()
|
|
440
440
|
return c
|
|
441
441
|
end
|
|
442
|
-
function Covenant:
|
|
443
|
-
local
|
|
442
|
+
function Covenant:checkComponentDefined(component)
|
|
443
|
+
local _undefinedStringifiedComponents = self.undefinedStringifiedComponents
|
|
444
444
|
local _arg0 = tostring(component)
|
|
445
|
-
local _arg0_1 =
|
|
446
|
-
local _arg1 = `Component {component} is already
|
|
445
|
+
local _arg0_1 = _undefinedStringifiedComponents[_arg0] ~= nil
|
|
446
|
+
local _arg1 = `Component {component} is already defined`
|
|
447
447
|
assert(_arg0_1, _arg1)
|
|
448
|
-
local
|
|
448
|
+
local _undefinedStringifiedComponents_1 = self.undefinedStringifiedComponents
|
|
449
449
|
local _arg0_2 = tostring(component)
|
|
450
|
-
|
|
450
|
+
_undefinedStringifiedComponents_1[_arg0_2] = nil
|
|
451
451
|
end
|
|
452
452
|
function Covenant:defineComponentNetworkBehavior(component, replicated, predictionValidator)
|
|
453
453
|
if replicated then
|
|
@@ -465,13 +465,13 @@ do
|
|
|
465
465
|
_stringifiedComponentValidators[_arg0_1] = _predictionValidator
|
|
466
466
|
end
|
|
467
467
|
end
|
|
468
|
-
function Covenant:
|
|
468
|
+
function Covenant:defineComputedComponent(_param)
|
|
469
469
|
local component = _param.component
|
|
470
470
|
local queriedComponents = _param.queriedComponents
|
|
471
471
|
local recipe = _param.recipe
|
|
472
472
|
local replicated = _param.replicated
|
|
473
473
|
local predictionValidator = _param.predictionValidator
|
|
474
|
-
self:
|
|
474
|
+
self:checkComponentDefined(component)
|
|
475
475
|
self:defineComponentNetworkBehavior(component, replicated, predictionValidator)
|
|
476
476
|
local queryThisComponent = self:worldQuery(component):cached()
|
|
477
477
|
local willUpdate = true
|
|
@@ -581,7 +581,7 @@ do
|
|
|
581
581
|
updater()
|
|
582
582
|
end)
|
|
583
583
|
end
|
|
584
|
-
function Covenant:
|
|
584
|
+
function Covenant:defineManagedChildren(_param)
|
|
585
585
|
local parentComponent = _param.parentComponent
|
|
586
586
|
local parentEntityTrackerComponent = _param.parentEntityTrackerComponent
|
|
587
587
|
local childIdentityComponent = _param.childIdentityComponent
|
|
@@ -590,9 +590,9 @@ do
|
|
|
590
590
|
local recipe = _param.recipe
|
|
591
591
|
local replicated = _param.replicated
|
|
592
592
|
local predictionValidator = _param.predictionValidator
|
|
593
|
-
self:
|
|
594
|
-
self:
|
|
595
|
-
self:
|
|
593
|
+
self:checkComponentDefined(parentComponent)
|
|
594
|
+
self:checkComponentDefined(parentEntityTrackerComponent)
|
|
595
|
+
self:checkComponentDefined(childIdentityComponent)
|
|
596
596
|
self:defineComponentNetworkBehavior(parentComponent, replicated, predictionValidator)
|
|
597
597
|
local queryParentComponent = self:worldQuery(parentComponent):cached()
|
|
598
598
|
local willUpdate = true
|
|
@@ -769,11 +769,11 @@ do
|
|
|
769
769
|
updater()
|
|
770
770
|
end)
|
|
771
771
|
end
|
|
772
|
-
function Covenant:
|
|
772
|
+
function Covenant:defineEntitySource(_param)
|
|
773
773
|
local identityComponent = _param.identityComponent
|
|
774
774
|
local recipe = _param.recipe
|
|
775
775
|
local replicated = _param.replicated
|
|
776
|
-
self:
|
|
776
|
+
self:checkComponentDefined(identityComponent)
|
|
777
777
|
self:defineComponentNetworkBehavior(identityComponent, replicated, false)
|
|
778
778
|
local willUpdate = true
|
|
779
779
|
local function indicateUpdate()
|
|
@@ -791,23 +791,29 @@ do
|
|
|
791
791
|
local _binding = recipe(lastUpdateId, hooks)
|
|
792
792
|
local statesToCreate = _binding.statesToCreate
|
|
793
793
|
local entitiesToDelete = _binding.entitiesToDelete
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
self:worldDelete(entity)
|
|
794
|
+
local _result = statesToCreate
|
|
795
|
+
if _result ~= nil then
|
|
796
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
797
|
+
local _callback = function(state)
|
|
798
|
+
local entity = self:worldEntity()
|
|
799
|
+
self:worldSet(entity, identityComponent, state)
|
|
800
|
+
end
|
|
801
|
+
for _k, _v in _result do
|
|
802
|
+
_callback(_v, _k - 1, _result)
|
|
803
|
+
end
|
|
804
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
806
805
|
end
|
|
807
|
-
|
|
808
|
-
|
|
806
|
+
local _result_1 = entitiesToDelete
|
|
807
|
+
if _result_1 ~= nil then
|
|
808
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
809
|
+
local _callback = function(entity)
|
|
810
|
+
self:worldDelete(entity)
|
|
811
|
+
end
|
|
812
|
+
for _k, _v in _result_1 do
|
|
813
|
+
_callback(_v, _k - 1, _result_1)
|
|
814
|
+
end
|
|
815
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
809
816
|
end
|
|
810
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
811
817
|
end
|
|
812
818
|
self:schedule(RunService.Heartbeat, function()
|
|
813
819
|
if not willUpdate then
|
package/src/hooks.luau
CHANGED
|
@@ -1,89 +1,112 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
-- eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
-
local function withUpdateId(fn)
|
|
4
|
-
local cache = nil
|
|
5
|
-
local lastUpdateId = -1
|
|
6
|
-
return function(id, ...)
|
|
7
|
-
local args = { ... }
|
|
8
|
-
if lastUpdateId ~= id then
|
|
9
|
-
cache = nil
|
|
10
|
-
lastUpdateId = id
|
|
11
|
-
end
|
|
12
|
-
if cache == nil then
|
|
13
|
-
cache = fn(unpack(args))
|
|
14
|
-
end
|
|
15
|
-
return cache
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
3
|
local function createUseEvent(_param)
|
|
19
4
|
local indicateUpdate = _param.indicateUpdate
|
|
20
5
|
local queues = {}
|
|
21
6
|
local watchedEvents = {}
|
|
22
|
-
local
|
|
7
|
+
local caches = {}
|
|
8
|
+
local lastUpdateId = -1
|
|
9
|
+
return function(updateId, event)
|
|
10
|
+
if lastUpdateId ~= updateId then
|
|
11
|
+
table.clear(caches)
|
|
12
|
+
lastUpdateId = updateId
|
|
13
|
+
end
|
|
23
14
|
local _event = event
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
local cache = caches[_event]
|
|
16
|
+
if cache ~= nil then
|
|
17
|
+
return cache
|
|
18
|
+
end
|
|
19
|
+
local _event_1 = event
|
|
20
|
+
if not (watchedEvents[_event_1] ~= nil) then
|
|
27
21
|
local _event_2 = event
|
|
28
|
-
|
|
22
|
+
watchedEvents[_event_2] = true
|
|
23
|
+
local _event_3 = event
|
|
24
|
+
queues[_event_3] = {}
|
|
29
25
|
event:Connect(function(...)
|
|
30
26
|
local args = { ... }
|
|
31
|
-
local
|
|
32
|
-
local _exp = queues[
|
|
27
|
+
local _event_4 = event
|
|
28
|
+
local _exp = queues[_event_4]
|
|
33
29
|
local _args = args
|
|
34
30
|
table.insert(_exp, _args)
|
|
35
31
|
indicateUpdate()
|
|
36
32
|
end)
|
|
33
|
+
local _event_4 = event
|
|
34
|
+
caches[_event_4] = {}
|
|
37
35
|
return {}
|
|
38
36
|
end
|
|
39
|
-
local
|
|
40
|
-
local queue = queues[
|
|
37
|
+
local _event_2 = event
|
|
38
|
+
local queue = queues[_event_2]
|
|
41
39
|
if not (#queue == 0) then
|
|
42
|
-
local
|
|
43
|
-
queues[
|
|
40
|
+
local _event_3 = event
|
|
41
|
+
queues[_event_3] = {}
|
|
44
42
|
end
|
|
43
|
+
local _event_3 = event
|
|
44
|
+
caches[_event_3] = queue
|
|
45
45
|
return queue
|
|
46
46
|
end
|
|
47
|
-
return withUpdateId(hook)
|
|
48
47
|
end
|
|
49
48
|
local function createUseEventImmediately(_param)
|
|
50
49
|
local indicateUpdate = _param.indicateUpdate
|
|
51
50
|
local queues = {}
|
|
52
51
|
local watchedEvents = {}
|
|
53
|
-
local
|
|
52
|
+
local caches = {}
|
|
53
|
+
local lastUpdateId = -1
|
|
54
|
+
return function(updateId, event, callback)
|
|
55
|
+
if lastUpdateId ~= updateId then
|
|
56
|
+
table.clear(caches)
|
|
57
|
+
lastUpdateId = updateId
|
|
58
|
+
end
|
|
54
59
|
local _event = event
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
local cache = caches[_event]
|
|
61
|
+
if cache ~= nil then
|
|
62
|
+
return cache
|
|
63
|
+
end
|
|
64
|
+
local _event_1 = event
|
|
65
|
+
if not (watchedEvents[_event_1] ~= nil) then
|
|
58
66
|
local _event_2 = event
|
|
59
|
-
|
|
67
|
+
watchedEvents[_event_2] = true
|
|
68
|
+
local _event_3 = event
|
|
69
|
+
queues[_event_3] = {}
|
|
60
70
|
event:Connect(function(...)
|
|
61
71
|
local args = { ... }
|
|
62
|
-
local
|
|
63
|
-
local _exp = queues[
|
|
72
|
+
local _event_4 = event
|
|
73
|
+
local _exp = queues[_event_4]
|
|
64
74
|
local _arg0 = callback(unpack(args))
|
|
65
75
|
table.insert(_exp, _arg0)
|
|
66
76
|
indicateUpdate()
|
|
67
77
|
end)
|
|
78
|
+
local _event_4 = event
|
|
79
|
+
caches[_event_4] = {}
|
|
68
80
|
return {}
|
|
69
81
|
end
|
|
70
|
-
local
|
|
71
|
-
local queue = queues[
|
|
82
|
+
local _event_2 = event
|
|
83
|
+
local queue = queues[_event_2]
|
|
72
84
|
if not (#queue == 0) then
|
|
73
|
-
local
|
|
74
|
-
queues[
|
|
85
|
+
local _event_3 = event
|
|
86
|
+
queues[_event_3] = {}
|
|
75
87
|
end
|
|
88
|
+
local _event_3 = event
|
|
89
|
+
caches[_event_3] = queue
|
|
76
90
|
return queue
|
|
77
91
|
end
|
|
78
|
-
return withUpdateId(hook)
|
|
79
92
|
end
|
|
80
93
|
local function createUseComponentChange(_param)
|
|
81
94
|
local subscribeComponent = _param.subscribeComponent
|
|
82
95
|
local update = _param.indicateUpdate
|
|
83
96
|
local queues = {}
|
|
84
97
|
local watchedStringifiedComponents = {}
|
|
85
|
-
local
|
|
98
|
+
local caches = {}
|
|
99
|
+
local lastUpdateId = -1
|
|
100
|
+
return function(updateId, component)
|
|
101
|
+
if lastUpdateId ~= updateId then
|
|
102
|
+
table.clear(caches)
|
|
103
|
+
lastUpdateId = updateId
|
|
104
|
+
end
|
|
86
105
|
local stringifiedComponent = tostring(component)
|
|
106
|
+
local cache = caches[stringifiedComponent]
|
|
107
|
+
if cache ~= nil then
|
|
108
|
+
return cache
|
|
109
|
+
end
|
|
87
110
|
if not (watchedStringifiedComponents[stringifiedComponent] ~= nil) then
|
|
88
111
|
watchedStringifiedComponents[stringifiedComponent] = true
|
|
89
112
|
queues[stringifiedComponent] = {}
|
|
@@ -97,15 +120,16 @@ local function createUseComponentChange(_param)
|
|
|
97
120
|
table.insert(_exp, _arg0)
|
|
98
121
|
update()
|
|
99
122
|
end)
|
|
123
|
+
caches[stringifiedComponent] = {}
|
|
100
124
|
return {}
|
|
101
125
|
end
|
|
102
126
|
local queue = queues[stringifiedComponent]
|
|
103
127
|
if not (#queue == 0) then
|
|
104
128
|
queues[stringifiedComponent] = {}
|
|
105
129
|
end
|
|
130
|
+
caches[stringifiedComponent] = queue
|
|
106
131
|
return queue
|
|
107
132
|
end
|
|
108
|
-
return withUpdateId(hook)
|
|
109
133
|
end
|
|
110
134
|
local function equalsDependencies(a, b)
|
|
111
135
|
if a == b then
|
|
@@ -135,27 +159,43 @@ end
|
|
|
135
159
|
local function createUseAsync(_param)
|
|
136
160
|
local indicateUpdate = _param.indicateUpdate
|
|
137
161
|
local storage = {}
|
|
138
|
-
local
|
|
162
|
+
local caches = {}
|
|
163
|
+
local lastUpdateId = -1
|
|
164
|
+
return function(updateId, asnycFactory, dependencies, discriminator)
|
|
165
|
+
if lastUpdateId ~= updateId then
|
|
166
|
+
table.clear(caches)
|
|
167
|
+
lastUpdateId = updateId
|
|
168
|
+
end
|
|
139
169
|
local _discriminator = discriminator
|
|
140
|
-
|
|
170
|
+
local cache = caches[_discriminator]
|
|
171
|
+
if cache ~= nil then
|
|
172
|
+
return cache
|
|
173
|
+
end
|
|
174
|
+
local _discriminator_1 = discriminator
|
|
175
|
+
if not (storage[_discriminator_1] ~= nil) then
|
|
141
176
|
local newResult = {
|
|
142
177
|
completed = false,
|
|
143
178
|
value = nil,
|
|
144
179
|
}
|
|
145
180
|
local thread = coroutine.create(executeThread)
|
|
146
181
|
coroutine.resume(thread, newResult, asnycFactory, indicateUpdate)
|
|
147
|
-
local
|
|
182
|
+
local _discriminator_2 = discriminator
|
|
148
183
|
local _arg1 = {
|
|
149
184
|
lastDependencies = dependencies,
|
|
150
185
|
thread = thread,
|
|
151
186
|
result = newResult,
|
|
152
187
|
}
|
|
153
|
-
storage[
|
|
188
|
+
storage[_discriminator_2] = _arg1
|
|
189
|
+
local _discriminator_3 = discriminator
|
|
190
|
+
caches[_discriminator_3] = newResult
|
|
154
191
|
return newResult
|
|
155
192
|
end
|
|
156
|
-
local
|
|
157
|
-
local state = storage[
|
|
193
|
+
local _discriminator_2 = discriminator
|
|
194
|
+
local state = storage[_discriminator_2]
|
|
158
195
|
if equalsDependencies(state.lastDependencies, dependencies) then
|
|
196
|
+
local _discriminator_3 = discriminator
|
|
197
|
+
local _result = state.result
|
|
198
|
+
caches[_discriminator_3] = _result
|
|
159
199
|
return state.result
|
|
160
200
|
else
|
|
161
201
|
coroutine.yield(state.thread)
|
|
@@ -166,39 +206,56 @@ local function createUseAsync(_param)
|
|
|
166
206
|
}
|
|
167
207
|
local newThread = coroutine.create(executeThread)
|
|
168
208
|
coroutine.resume(newThread, newResult, asnycFactory, indicateUpdate)
|
|
169
|
-
local
|
|
209
|
+
local _discriminator_3 = discriminator
|
|
170
210
|
local _arg1 = {
|
|
171
211
|
lastDependencies = dependencies,
|
|
172
212
|
thread = newThread,
|
|
173
213
|
result = newResult,
|
|
174
214
|
}
|
|
175
|
-
storage[
|
|
215
|
+
storage[_discriminator_3] = _arg1
|
|
216
|
+
local _discriminator_4 = discriminator
|
|
217
|
+
caches[_discriminator_4] = newResult
|
|
176
218
|
return newResult
|
|
177
219
|
end
|
|
178
220
|
end
|
|
179
|
-
return withUpdateId(hook)
|
|
180
221
|
end
|
|
181
222
|
local function createUseImperative(_param)
|
|
182
223
|
local indicateUpdate = _param.indicateUpdate
|
|
183
224
|
local storage = {}
|
|
184
|
-
local
|
|
225
|
+
local caches = {}
|
|
226
|
+
local lastUpdateId = -1
|
|
227
|
+
return function(updateId, dirtyFactory, dependencies, discriminator)
|
|
228
|
+
if lastUpdateId ~= updateId then
|
|
229
|
+
table.clear(caches)
|
|
230
|
+
lastUpdateId = updateId
|
|
231
|
+
end
|
|
185
232
|
local _discriminator = discriminator
|
|
186
|
-
|
|
233
|
+
local cache = caches[_discriminator]
|
|
234
|
+
if cache ~= nil then
|
|
235
|
+
return cache
|
|
236
|
+
end
|
|
237
|
+
local _discriminator_1 = discriminator
|
|
238
|
+
if not (storage[_discriminator_1] ~= nil) then
|
|
187
239
|
local _binding = dirtyFactory(indicateUpdate)
|
|
188
240
|
local value = _binding.value
|
|
189
241
|
local cleanup = _binding.cleanup
|
|
190
|
-
local
|
|
242
|
+
local _discriminator_2 = discriminator
|
|
191
243
|
local _arg1 = {
|
|
192
244
|
cache = value,
|
|
193
245
|
cleanup = cleanup,
|
|
194
246
|
lastDependencies = dependencies,
|
|
195
247
|
}
|
|
196
|
-
storage[
|
|
248
|
+
storage[_discriminator_2] = _arg1
|
|
249
|
+
local _discriminator_3 = discriminator
|
|
250
|
+
caches[_discriminator_3] = value
|
|
197
251
|
return value
|
|
198
252
|
end
|
|
199
|
-
local
|
|
200
|
-
local state = storage[
|
|
253
|
+
local _discriminator_2 = discriminator
|
|
254
|
+
local state = storage[_discriminator_2]
|
|
201
255
|
if equalsDependencies(state.lastDependencies, dependencies) then
|
|
256
|
+
local _discriminator_3 = discriminator
|
|
257
|
+
local _cache = state.cache
|
|
258
|
+
caches[_discriminator_3] = _cache
|
|
202
259
|
return state.cache
|
|
203
260
|
else
|
|
204
261
|
if state.cleanup ~= nil then
|
|
@@ -207,66 +264,100 @@ local function createUseImperative(_param)
|
|
|
207
264
|
local _binding = dirtyFactory(indicateUpdate)
|
|
208
265
|
local value = _binding.value
|
|
209
266
|
local cleanup = _binding.cleanup
|
|
210
|
-
local
|
|
267
|
+
local _discriminator_3 = discriminator
|
|
211
268
|
local _arg1 = {
|
|
212
269
|
cache = value,
|
|
213
270
|
cleanup = cleanup,
|
|
214
271
|
lastDependencies = dependencies,
|
|
215
272
|
}
|
|
216
|
-
storage[
|
|
273
|
+
storage[_discriminator_3] = _arg1
|
|
274
|
+
local _discriminator_4 = discriminator
|
|
275
|
+
caches[_discriminator_4] = value
|
|
217
276
|
return value
|
|
218
277
|
end
|
|
219
278
|
end
|
|
220
|
-
return withUpdateId(hook)
|
|
221
279
|
end
|
|
222
280
|
local function createUseChange()
|
|
223
281
|
local dependenciesStorage = {}
|
|
224
|
-
local
|
|
282
|
+
local caches = {}
|
|
283
|
+
local lastUpdateId = -1
|
|
284
|
+
return function(updateId, dependencies, discriminator)
|
|
285
|
+
if lastUpdateId ~= updateId then
|
|
286
|
+
table.clear(caches)
|
|
287
|
+
lastUpdateId = updateId
|
|
288
|
+
end
|
|
225
289
|
local _discriminator = discriminator
|
|
226
|
-
|
|
227
|
-
|
|
290
|
+
local cache = caches[_discriminator]
|
|
291
|
+
if cache ~= nil then
|
|
292
|
+
return cache
|
|
293
|
+
end
|
|
294
|
+
local _discriminator_1 = discriminator
|
|
295
|
+
if not (dependenciesStorage[_discriminator_1] ~= nil) then
|
|
296
|
+
local _discriminator_2 = discriminator
|
|
228
297
|
local _dependencies = dependencies
|
|
229
|
-
dependenciesStorage[
|
|
298
|
+
dependenciesStorage[_discriminator_2] = _dependencies
|
|
299
|
+
local _discriminator_3 = discriminator
|
|
300
|
+
caches[_discriminator_3] = true
|
|
230
301
|
return true
|
|
231
302
|
end
|
|
232
|
-
local
|
|
233
|
-
local lastDependencies = dependenciesStorage[
|
|
303
|
+
local _discriminator_2 = discriminator
|
|
304
|
+
local lastDependencies = dependenciesStorage[_discriminator_2]
|
|
234
305
|
if equalsDependencies(lastDependencies, dependencies) then
|
|
306
|
+
local _discriminator_3 = discriminator
|
|
307
|
+
caches[_discriminator_3] = false
|
|
235
308
|
return false
|
|
236
309
|
else
|
|
237
|
-
local
|
|
310
|
+
local _discriminator_3 = discriminator
|
|
238
311
|
local _dependencies = dependencies
|
|
239
|
-
dependenciesStorage[
|
|
312
|
+
dependenciesStorage[_discriminator_3] = _dependencies
|
|
313
|
+
local _discriminator_4 = discriminator
|
|
314
|
+
caches[_discriminator_4] = true
|
|
240
315
|
return true
|
|
241
316
|
end
|
|
242
317
|
end
|
|
243
|
-
return withUpdateId(hook)
|
|
244
318
|
end
|
|
245
319
|
local function createUseInterval(_param)
|
|
246
320
|
local indicateUpdate = _param.indicateUpdate
|
|
247
321
|
local nextClocks = {}
|
|
248
|
-
local
|
|
322
|
+
local caches = {}
|
|
323
|
+
local lastUpdateId = -1
|
|
324
|
+
return function(updateId, seconds, trueOnInit, discriminator)
|
|
325
|
+
if lastUpdateId ~= updateId then
|
|
326
|
+
table.clear(caches)
|
|
327
|
+
lastUpdateId = updateId
|
|
328
|
+
end
|
|
249
329
|
local _discriminator = discriminator
|
|
250
|
-
|
|
251
|
-
|
|
330
|
+
local cache = caches[_discriminator]
|
|
331
|
+
if cache ~= nil then
|
|
332
|
+
return cache
|
|
333
|
+
end
|
|
334
|
+
local _discriminator_1 = discriminator
|
|
335
|
+
if not (nextClocks[_discriminator_1] ~= nil) then
|
|
336
|
+
local _discriminator_2 = discriminator
|
|
252
337
|
local _arg1 = os.clock() + seconds
|
|
253
|
-
nextClocks[
|
|
338
|
+
nextClocks[_discriminator_2] = _arg1
|
|
254
339
|
task.delay(seconds, indicateUpdate)
|
|
340
|
+
local _discriminator_3 = discriminator
|
|
341
|
+
local _trueOnInit = trueOnInit
|
|
342
|
+
caches[_discriminator_3] = _trueOnInit
|
|
255
343
|
return trueOnInit
|
|
256
344
|
end
|
|
257
|
-
local
|
|
258
|
-
local nextClock = nextClocks[
|
|
345
|
+
local _discriminator_2 = discriminator
|
|
346
|
+
local nextClock = nextClocks[_discriminator_2]
|
|
259
347
|
if nextClock < os.clock() then
|
|
348
|
+
local _discriminator_3 = discriminator
|
|
349
|
+
caches[_discriminator_3] = false
|
|
260
350
|
return false
|
|
261
351
|
else
|
|
262
|
-
local
|
|
352
|
+
local _discriminator_3 = discriminator
|
|
263
353
|
local _arg1 = os.clock() + seconds
|
|
264
|
-
nextClocks[
|
|
354
|
+
nextClocks[_discriminator_3] = _arg1
|
|
265
355
|
task.delay(seconds, indicateUpdate)
|
|
356
|
+
local _discriminator_4 = discriminator
|
|
357
|
+
caches[_discriminator_4] = true
|
|
266
358
|
return true
|
|
267
359
|
end
|
|
268
360
|
end
|
|
269
|
-
return withUpdateId(hook)
|
|
270
361
|
end
|
|
271
362
|
local function createHooks(props)
|
|
272
363
|
return {
|