@latticexyz/recs 2.0.12-main-d7526607 → 2.0.12-main-96e7bf43

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/src/utils.ts DELETED
@@ -1,68 +0,0 @@
1
- import { map, pipe } from "rxjs";
2
- import { getComponentValue } from "./Component";
3
- import { UpdateType } from "./constants";
4
- import { Component, ComponentUpdate, ComponentValue, Entity, Indexer, Schema } from "./types";
5
-
6
- /**
7
- * Type guard to infer the TypeScript type of a given component update
8
- *
9
- * @param update Component update to infer the type of.
10
- * @param component {@link defineComponent Component} to check whether the given update corresponds to it.
11
- * @returns True (+ infered type for `update`) if `update` belongs to `component`. Else false.
12
- */
13
- export function isComponentUpdate<S extends Schema>(
14
- update: ComponentUpdate,
15
- component: Component<S>,
16
- ): update is ComponentUpdate<S> {
17
- return update.component === component;
18
- }
19
-
20
- /**
21
- * Helper function to create a component update for the current component value of a given entity.
22
- *
23
- * @param entity Entity to create the component update for.
24
- * @param component Component to create the component update for.
25
- * @returns Component update corresponding to the given entity, the given component and the entity's current component value.
26
- */
27
- export function toUpdate<S extends Schema>(entity: Entity, component: Component<S>) {
28
- const value = getComponentValue(component, entity);
29
- return {
30
- entity,
31
- component,
32
- value: [value, undefined],
33
- type: value == null ? UpdateType.Noop : UpdateType.Enter,
34
- } as ComponentUpdate<S> & {
35
- type: UpdateType;
36
- };
37
- }
38
-
39
- /**
40
- * Helper function to turn a stream of {@link Entity Entities} into a stream of component updates of the given component.
41
- * @param component Component to create update stream for.
42
- * @returns Unary function to be used with RxJS that turns stream of {@link Entity Entities} into stream of component updates.
43
- */
44
- export function toUpdateStream<S extends Schema>(component: Component<S>) {
45
- return pipe(map((entity: Entity) => toUpdate(entity, component)));
46
- }
47
-
48
- /**
49
- * Helper function to check whether a given component is indexed.
50
- * @param c
51
- * @returns
52
- */
53
- export function isIndexer<S extends Schema>(c: Component<S> | Indexer<S>): c is Indexer<S> {
54
- return "getEntitiesWithValue" in c;
55
- }
56
-
57
- /**
58
- * Helper function to check whether a given component value is partial or full.
59
- * @param component
60
- * @param value
61
- * @returns
62
- */
63
- export function isFullComponentValue<S extends Schema>(
64
- component: Component<S>,
65
- value: Partial<ComponentValue<S>>,
66
- ): value is ComponentValue<S> {
67
- return Object.keys(component.schema).every((key) => key in value);
68
- }