@rbxts/covenant 3.4.0 → 3.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/covenant",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.luau CHANGED
@@ -570,6 +570,18 @@ do
570
570
  subscribeComponent = function(component, subscriber)
571
571
  self:subscribeComponent(component, subscriber)
572
572
  end,
573
+ getPayloadQueue = function(component)
574
+ local queue = {}
575
+ for entity, state in self:worldQuery(component) do
576
+ local _arg0 = {
577
+ entity = entity,
578
+ state = state,
579
+ previousState = nil,
580
+ }
581
+ table.insert(queue, _arg0)
582
+ end
583
+ return queue
584
+ end,
573
585
  })
574
586
  -- ▼ ReadonlyArray.map ▼
575
587
  local _newValue = table.create(#queriedComponents)
package/src/hooks.d.ts CHANGED
@@ -8,7 +8,7 @@ export type Discriminator = Exclude<defined, number>;
8
8
  export interface CovenantHooks {
9
9
  useEvent: <T extends Array<unknown>>(updateId: number, instance: Instance, event: RBXScriptSignal<(...args: T) => void>) => T[];
10
10
  useEventImmediately: <T extends Array<unknown>, TReturn extends defined>(updateId: number, instance: Instance, event: RBXScriptSignal<(...args: T) => void>, callback: (...args: T) => TReturn) => TReturn[];
11
- useComponentChange: <T extends defined>(updateId: number, component: Entity<T>) => {
11
+ useComponentChange: <T extends defined>(updateId: number, component: Entity<T>, payload: boolean) => {
12
12
  entity: Entity;
13
13
  state: T | undefined;
14
14
  previousState: T | undefined;
@@ -24,6 +24,11 @@ export interface CovenantHooks {
24
24
  interface CovenantHooksProps {
25
25
  indicateUpdate: () => void;
26
26
  subscribeComponent: <T extends defined>(component: Entity<T>, subscriber: (entity: Entity, state: T | undefined, previousState: T | undefined) => void) => void;
27
+ getPayloadQueue: <T extends defined>(component: Entity<T>) => {
28
+ entity: Entity;
29
+ state: T | undefined;
30
+ previousState: T | undefined;
31
+ }[];
27
32
  }
28
33
  export declare function createHooks(props: CovenantHooksProps): CovenantHooks;
29
34
  export {};
package/src/hooks.luau CHANGED
@@ -78,12 +78,16 @@ local function createUseEventImmediately(_param)
78
78
  end
79
79
  local function createUseComponentChange(_param)
80
80
  local subscribeComponent = _param.subscribeComponent
81
- local update = _param.indicateUpdate
81
+ local indicateUpdate = _param.indicateUpdate
82
+ local getPayloadQueue = _param.getPayloadQueue
82
83
  local queues = {}
83
84
  local watchedStringifiedComponents = {}
84
85
  local caches = {}
85
86
  local lastUpdateId = -1
86
- return function(updateId, component)
87
+ return function(updateId, component, payload)
88
+ if payload == nil then
89
+ payload = false
90
+ end
87
91
  if lastUpdateId ~= updateId then
88
92
  table.clear(caches)
89
93
  lastUpdateId = updateId
@@ -104,10 +108,14 @@ local function createUseComponentChange(_param)
104
108
  previousState = previousState,
105
109
  }
106
110
  table.insert(_exp, _arg0)
107
- update()
111
+ indicateUpdate()
108
112
  end)
109
113
  caches[stringifiedComponent] = {}
110
- return {}
114
+ if not payload then
115
+ return {}
116
+ else
117
+ return getPayloadQueue(component)
118
+ end
111
119
  end
112
120
  local queue = queues[stringifiedComponent]
113
121
  if not (#queue == 0) then