@rbxts/covenant 3.3.7 → 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.3.7",
3
+ "version": "3.5.0",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface CovenantProps {
14
14
  predictionSend: (worldChanges: WorldChangesForPrediction) => void;
15
15
  predictionConnect: (callback: (player: Player, worldChanges: WorldChangesForPrediction) => void) => void;
16
16
  }
17
+ type ComponentSubscriber<T extends defined = defined> = (entity: Entity, state: T | undefined, previousState: T | undefined, isDeleting: boolean) => void;
17
18
  type ComponentPredictionValidator = (player: Player, entity: Entity, newState: unknown, lastState: unknown) => boolean;
18
19
  export declare class Covenant {
19
20
  private _world;
@@ -55,7 +56,7 @@ export declare class Covenant {
55
56
  private preventPostStartCall;
56
57
  private schedule;
57
58
  private worldSet;
58
- subscribeComponent<T>(component: Entity<T>, subscriber: (entity: Entity, state: T | undefined, previousState: T | undefined) => void): () => void;
59
+ subscribeComponent<T extends defined>(component: Entity<T>, subscriber: ComponentSubscriber<T>): () => void;
59
60
  private worldDelete;
60
61
  worldComponent<T extends defined>(name: string): Entity<T>;
61
62
  getComponentName(component: Entity): string;
package/src/covenant.luau CHANGED
@@ -387,7 +387,7 @@ do
387
387
  if _result ~= nil then
388
388
  -- ▼ ReadonlySet.forEach ▼
389
389
  local _callback = function(subscriber)
390
- subscriber(entity, newState, lastState)
390
+ subscriber(entity, newState, lastState, false)
391
391
  end
392
392
  for _v in _result do
393
393
  _callback(_v, _v, _result)
@@ -482,7 +482,7 @@ do
482
482
  if _result ~= nil then
483
483
  -- ▼ ReadonlySet.forEach ▼
484
484
  local _callback_1 = function(subscriber)
485
- subscriber(entity, nil, lastState)
485
+ subscriber(entity, nil, lastState, false)
486
486
  end
487
487
  for _v in _result do
488
488
  _callback_1(_v, _v, _result)
@@ -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