@rbxts/covenant 3.6.0 → 3.7.0
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 +48 -48
- package/src/covenant.luau +1 -15
- package/src/hooks.d.ts +6 -6
- package/src/hooks.luau +71 -4
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@rbxts/covenant",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"main": "src/init.luau",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "rbxtsc",
|
|
7
|
-
"watch": "rbxtsc -w",
|
|
8
|
-
"prepublishOnly": "npm run build"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/cuberootmctoasted/covenant.git"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"bugs": {
|
|
18
|
-
"url": "https://github.com/cuberootmctoasted/covenant/issues"
|
|
19
|
-
},
|
|
20
|
-
"homepage": "https://github.com/cuberootmctoasted/covenant#readme",
|
|
21
|
-
"description": "",
|
|
22
|
-
"types": "src/covenant.d.ts",
|
|
23
|
-
"files": [
|
|
24
|
-
"src",
|
|
25
|
-
"!**/*.tsbuildinfo"
|
|
26
|
-
],
|
|
27
|
-
"publishConfig": {
|
|
28
|
-
"access": "public"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
32
|
-
"@rbxts/covenant": "^2.1.1",
|
|
33
|
-
"@rbxts/types": "^1.0.891",
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
35
|
-
"@typescript-eslint/parser": "^8.47.0",
|
|
36
|
-
"eslint": "^9.39.1",
|
|
37
|
-
"eslint-config-prettier": "^10.1.8",
|
|
38
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
39
|
-
"eslint-plugin-roblox-ts": "^1.3.0",
|
|
40
|
-
"prettier": "^3.6.2",
|
|
41
|
-
"roblox-ts": "^3.0.0",
|
|
42
|
-
"typescript": "^5.9.3"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"@rbxts/jecs": "^0.9.0",
|
|
46
|
-
"@rbxts/services": "^1.6.0"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@rbxts/covenant",
|
|
3
|
+
"version": "3.7.0",
|
|
4
|
+
"main": "src/init.luau",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "rbxtsc",
|
|
7
|
+
"watch": "rbxtsc -w",
|
|
8
|
+
"prepublishOnly": "npm run build"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/cuberootmctoasted/covenant.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/cuberootmctoasted/covenant/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/cuberootmctoasted/covenant#readme",
|
|
21
|
+
"description": "",
|
|
22
|
+
"types": "src/covenant.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"!**/*.tsbuildinfo"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
32
|
+
"@rbxts/covenant": "^2.1.1",
|
|
33
|
+
"@rbxts/types": "^1.0.891",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
36
|
+
"eslint": "^9.39.1",
|
|
37
|
+
"eslint-config-prettier": "^10.1.8",
|
|
38
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
39
|
+
"eslint-plugin-roblox-ts": "^1.3.0",
|
|
40
|
+
"prettier": "^3.6.2",
|
|
41
|
+
"roblox-ts": "^3.0.0",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@rbxts/jecs": "^0.9.0",
|
|
46
|
+
"@rbxts/services": "^1.6.0"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/covenant.luau
CHANGED
|
@@ -578,21 +578,7 @@ do
|
|
|
578
578
|
end
|
|
579
579
|
local hooks = createHooks({
|
|
580
580
|
indicateUpdate = indicateUpdate,
|
|
581
|
-
|
|
582
|
-
self:subscribeComponent(component, subscriber)
|
|
583
|
-
end,
|
|
584
|
-
getPayloadQueue = function(component)
|
|
585
|
-
local queue = {}
|
|
586
|
-
for entity, state in self:worldQuery(component) do
|
|
587
|
-
local _arg0 = {
|
|
588
|
-
entity = entity,
|
|
589
|
-
state = state,
|
|
590
|
-
previousState = nil,
|
|
591
|
-
}
|
|
592
|
-
table.insert(queue, _arg0)
|
|
593
|
-
end
|
|
594
|
-
return queue
|
|
595
|
-
end,
|
|
581
|
+
covenant = self,
|
|
596
582
|
})
|
|
597
583
|
-- ▼ ReadonlyArray.map ▼
|
|
598
584
|
local _newValue = table.create(#queriedComponents)
|
package/src/hooks.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Entity } from "@rbxts/jecs";
|
|
2
|
+
import { Covenant } from "./covenant";
|
|
2
3
|
type AsyncResult<T = unknown> = {
|
|
3
4
|
completed: boolean;
|
|
4
5
|
value: T | undefined;
|
|
@@ -13,6 +14,10 @@ export interface CovenantHooks {
|
|
|
13
14
|
state: T | undefined;
|
|
14
15
|
previousState: T | undefined;
|
|
15
16
|
}[];
|
|
17
|
+
useComponentChangeOfEntity: <T extends defined>(updateId: number, entity: Entity, component: Entity<T>, payload: boolean) => {
|
|
18
|
+
state: T | undefined;
|
|
19
|
+
previousState: T | undefined;
|
|
20
|
+
} | undefined;
|
|
16
21
|
useAsync: <T>(updateId: number, asnycFactory: () => T, dependencies: unknown[], discriminator: Discriminator) => AsyncResult<T>;
|
|
17
22
|
useImperative: <T extends defined>(updateId: number, dirtyFactory: (indicateUpdate: () => void) => {
|
|
18
23
|
value: T;
|
|
@@ -23,12 +28,7 @@ export interface CovenantHooks {
|
|
|
23
28
|
}
|
|
24
29
|
interface CovenantHooksProps {
|
|
25
30
|
indicateUpdate: () => void;
|
|
26
|
-
|
|
27
|
-
getPayloadQueue: <T extends defined>(component: Entity<T>) => {
|
|
28
|
-
entity: Entity;
|
|
29
|
-
state: T | undefined;
|
|
30
|
-
previousState: T | undefined;
|
|
31
|
-
}[];
|
|
31
|
+
covenant: Covenant;
|
|
32
32
|
}
|
|
33
33
|
export declare function createHooks(props: CovenantHooksProps): CovenantHooks;
|
|
34
34
|
export {};
|
package/src/hooks.luau
CHANGED
|
@@ -77,9 +77,8 @@ local function createUseEventImmediately(_param)
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
local function createUseComponentChange(_param)
|
|
80
|
-
local
|
|
80
|
+
local covenant = _param.covenant
|
|
81
81
|
local indicateUpdate = _param.indicateUpdate
|
|
82
|
-
local getPayloadQueue = _param.getPayloadQueue
|
|
83
82
|
local queues = {}
|
|
84
83
|
local watchedStringifiedComponents = {}
|
|
85
84
|
local caches = {}
|
|
@@ -100,7 +99,7 @@ local function createUseComponentChange(_param)
|
|
|
100
99
|
if not (watchedStringifiedComponents[stringifiedComponent] ~= nil) then
|
|
101
100
|
watchedStringifiedComponents[stringifiedComponent] = true
|
|
102
101
|
queues[stringifiedComponent] = {}
|
|
103
|
-
subscribeComponent(component, function(entity, state, previousState)
|
|
102
|
+
covenant:subscribeComponent(component, function(entity, state, previousState)
|
|
104
103
|
local _exp = queues[stringifiedComponent]
|
|
105
104
|
local _arg0 = {
|
|
106
105
|
entity = entity,
|
|
@@ -114,7 +113,16 @@ local function createUseComponentChange(_param)
|
|
|
114
113
|
if not payload then
|
|
115
114
|
return {}
|
|
116
115
|
else
|
|
117
|
-
|
|
116
|
+
local payloadQueue = {}
|
|
117
|
+
for entity, state in covenant:worldQuery(component) do
|
|
118
|
+
local _arg0 = {
|
|
119
|
+
entity = entity,
|
|
120
|
+
state = state,
|
|
121
|
+
previousState = nil,
|
|
122
|
+
}
|
|
123
|
+
table.insert(payloadQueue, _arg0)
|
|
124
|
+
end
|
|
125
|
+
return payloadQueue
|
|
118
126
|
end
|
|
119
127
|
end
|
|
120
128
|
local queue = queues[stringifiedComponent]
|
|
@@ -125,6 +133,64 @@ local function createUseComponentChange(_param)
|
|
|
125
133
|
return queue
|
|
126
134
|
end
|
|
127
135
|
end
|
|
136
|
+
local function createUseComponentChangeOfEntity(_param)
|
|
137
|
+
local covenant = _param.covenant
|
|
138
|
+
local indicateUpdate = _param.indicateUpdate
|
|
139
|
+
local changes = {}
|
|
140
|
+
local watchedStringifiedComponents = {}
|
|
141
|
+
local caches = {}
|
|
142
|
+
local lastUpdateId = -1
|
|
143
|
+
return function(updateId, entity, component, payload)
|
|
144
|
+
if payload == nil then
|
|
145
|
+
payload = false
|
|
146
|
+
end
|
|
147
|
+
if lastUpdateId ~= updateId then
|
|
148
|
+
table.clear(caches)
|
|
149
|
+
lastUpdateId = updateId
|
|
150
|
+
end
|
|
151
|
+
local stringifiedComponent = tostring(component)
|
|
152
|
+
local cache = caches[stringifiedComponent]
|
|
153
|
+
if cache ~= nil then
|
|
154
|
+
return if cache == false then nil else cache
|
|
155
|
+
end
|
|
156
|
+
if not (watchedStringifiedComponents[stringifiedComponent] ~= nil) then
|
|
157
|
+
watchedStringifiedComponents[stringifiedComponent] = true
|
|
158
|
+
covenant:subscribeComponent(component, function(anEntity, state, previousState)
|
|
159
|
+
if entity ~= anEntity then
|
|
160
|
+
return nil
|
|
161
|
+
end
|
|
162
|
+
local _arg1 = {
|
|
163
|
+
state = state,
|
|
164
|
+
previousState = previousState,
|
|
165
|
+
}
|
|
166
|
+
changes[stringifiedComponent] = _arg1
|
|
167
|
+
indicateUpdate()
|
|
168
|
+
end)
|
|
169
|
+
caches[stringifiedComponent] = false
|
|
170
|
+
if not payload then
|
|
171
|
+
return nil
|
|
172
|
+
else
|
|
173
|
+
if not covenant:worldContains(entity) then
|
|
174
|
+
return nil
|
|
175
|
+
end
|
|
176
|
+
local state = covenant:worldGet(entity, component)
|
|
177
|
+
if state == nil then
|
|
178
|
+
return nil
|
|
179
|
+
end
|
|
180
|
+
return {
|
|
181
|
+
state = state,
|
|
182
|
+
previousState = nil,
|
|
183
|
+
}
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
local change = changes[stringifiedComponent]
|
|
187
|
+
if change ~= nil then
|
|
188
|
+
changes[stringifiedComponent] = nil
|
|
189
|
+
end
|
|
190
|
+
caches[stringifiedComponent] = change
|
|
191
|
+
return change
|
|
192
|
+
end
|
|
193
|
+
end
|
|
128
194
|
local function equalsDependencies(a, b)
|
|
129
195
|
if a == b then
|
|
130
196
|
return true
|
|
@@ -357,6 +423,7 @@ local function createHooks(props)
|
|
|
357
423
|
useEvent = createUseEvent(props),
|
|
358
424
|
useEventImmediately = createUseEventImmediately(props),
|
|
359
425
|
useComponentChange = createUseComponentChange(props),
|
|
426
|
+
useComponentChangeOfEntity = createUseComponentChangeOfEntity(props),
|
|
360
427
|
useAsync = createUseAsync(props),
|
|
361
428
|
useImperative = createUseImperative(props),
|
|
362
429
|
useChange = createUseChange(),
|