@gamedev-sensei/react-extras 1.1.1

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @gamedev-sensei/react-extras
2
+
3
+ Provides some useful ReactJs hooks:
4
+
5
+ * `useDerived` - works the same as the `useMemo` hook, but guarantees that the value will not be recomputed unless the dependencies change.
6
+ You can specify a custom comparison function as the third parameter.
7
+ * `useMount` - works as the same as the `useEffect` hook, but you cannot specify the dependencies and the callback is run on component mount.
8
+
9
+ ## Installation
10
+
11
+ Yarn:
12
+ ```bash
13
+ yarn add @gamedev-sensei/react-extras
14
+ ```
15
+
16
+ Npm:
17
+ ```bash
18
+ npm i @gamedev-sensei/react-extras
19
+ ```
@@ -0,0 +1,34 @@
1
+ import * as react from 'react';
2
+ import { DependencyList } from 'react';
3
+
4
+ type WithId<T extends object> = T extends object ? (T & {
5
+ id: string;
6
+ }) : never;
7
+ type WithoutId<T extends object> = T extends object ? Omit<T, "id"> : never;
8
+ declare const withId: <T extends object>(v: T, id: string) => WithId<T>;
9
+ declare const withoutId: <T extends object>({ id, ...v }: WithId<T>) => WithoutId<WithId<T>>;
10
+ type ArrayWithId<T extends object> = WithId<T>[];
11
+ type ArrayWithoutId<T extends object> = WithoutId<WithId<T>>[];
12
+ declare const arrayWithIds: <T extends object>(v: T[], idGenerator: () => string) => ArrayWithId<T>;
13
+ declare const arrayWithoutIds: <T extends object>(v: ArrayWithId<T>) => ArrayWithoutId<T>;
14
+ declare function wrapIdGenerator(generator: () => string): (() => string) & {
15
+ withId<T extends {}>(v: T): WithId<T>;
16
+ arrayWithIds<T extends {}>(v: T[]): ArrayWithId<T>;
17
+ };
18
+ type IdGenerator = ReturnType<typeof wrapIdGenerator>;
19
+
20
+ declare function useIdGenerator(): IdGenerator;
21
+
22
+ declare function useProvidedIdGenerator(): IdGenerator;
23
+
24
+ declare const IdGeneratorProvider: react.Provider<(() => string) & {
25
+ withId<T extends {}>(v: T): WithId<T>;
26
+ arrayWithIds<T extends {}>(v: T[]): ArrayWithId<T>;
27
+ }>;
28
+
29
+ declare function useDerived<T>(factory: () => T, dependencies: DependencyList, compareFn?: (a: unknown, b: unknown) => boolean): T;
30
+
31
+ type CleanupFunction = () => void;
32
+ declare function useMount(callback: () => (CleanupFunction | void)): void;
33
+
34
+ export { type ArrayWithId, type ArrayWithoutId, type IdGenerator, IdGeneratorProvider, type WithId, type WithoutId, arrayWithIds, arrayWithoutIds, useDerived, useIdGenerator, useMount, useProvidedIdGenerator, withId, withoutId, wrapIdGenerator };
@@ -0,0 +1,34 @@
1
+ import * as react from 'react';
2
+ import { DependencyList } from 'react';
3
+
4
+ type WithId<T extends object> = T extends object ? (T & {
5
+ id: string;
6
+ }) : never;
7
+ type WithoutId<T extends object> = T extends object ? Omit<T, "id"> : never;
8
+ declare const withId: <T extends object>(v: T, id: string) => WithId<T>;
9
+ declare const withoutId: <T extends object>({ id, ...v }: WithId<T>) => WithoutId<WithId<T>>;
10
+ type ArrayWithId<T extends object> = WithId<T>[];
11
+ type ArrayWithoutId<T extends object> = WithoutId<WithId<T>>[];
12
+ declare const arrayWithIds: <T extends object>(v: T[], idGenerator: () => string) => ArrayWithId<T>;
13
+ declare const arrayWithoutIds: <T extends object>(v: ArrayWithId<T>) => ArrayWithoutId<T>;
14
+ declare function wrapIdGenerator(generator: () => string): (() => string) & {
15
+ withId<T extends {}>(v: T): WithId<T>;
16
+ arrayWithIds<T extends {}>(v: T[]): ArrayWithId<T>;
17
+ };
18
+ type IdGenerator = ReturnType<typeof wrapIdGenerator>;
19
+
20
+ declare function useIdGenerator(): IdGenerator;
21
+
22
+ declare function useProvidedIdGenerator(): IdGenerator;
23
+
24
+ declare const IdGeneratorProvider: react.Provider<(() => string) & {
25
+ withId<T extends {}>(v: T): WithId<T>;
26
+ arrayWithIds<T extends {}>(v: T[]): ArrayWithId<T>;
27
+ }>;
28
+
29
+ declare function useDerived<T>(factory: () => T, dependencies: DependencyList, compareFn?: (a: unknown, b: unknown) => boolean): T;
30
+
31
+ type CleanupFunction = () => void;
32
+ declare function useMount(callback: () => (CleanupFunction | void)): void;
33
+
34
+ export { type ArrayWithId, type ArrayWithoutId, type IdGenerator, IdGeneratorProvider, type WithId, type WithoutId, arrayWithIds, arrayWithoutIds, useDerived, useIdGenerator, useMount, useProvidedIdGenerator, withId, withoutId, wrapIdGenerator };
package/dist/index.js ADDED
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ IdGeneratorProvider: () => IdGeneratorProvider,
24
+ arrayWithIds: () => arrayWithIds,
25
+ arrayWithoutIds: () => arrayWithoutIds,
26
+ useDerived: () => useDerived,
27
+ useIdGenerator: () => useIdGenerator,
28
+ useMount: () => useMount,
29
+ useProvidedIdGenerator: () => useProvidedIdGenerator,
30
+ withId: () => withId,
31
+ withoutId: () => withoutId,
32
+ wrapIdGenerator: () => wrapIdGenerator
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // src/idGenerator/generator.ts
37
+ var withId = (v, id) => ({ ...v, id });
38
+ var withoutId = ({ id, ...v }) => v;
39
+ var arrayWithIds = (v, idGenerator) => v.map((i) => withId(i, idGenerator()));
40
+ var arrayWithoutIds = (v) => v.map(withoutId);
41
+ function wrapIdGenerator(generator) {
42
+ return Object.assign(generator, {
43
+ withId(v) {
44
+ return withId(v, generator());
45
+ },
46
+ arrayWithIds(v) {
47
+ return arrayWithIds(v, generator);
48
+ }
49
+ });
50
+ }
51
+
52
+ // src/idGenerator/useIdGenerator.ts
53
+ var import_react2 = require("react");
54
+
55
+ // src/useDerived.ts
56
+ var import_react = require("react");
57
+ function equals(x, y) {
58
+ if (typeof x === "number" && typeof y === "number") {
59
+ return x === y || x !== x && y !== y;
60
+ }
61
+ return x === y;
62
+ }
63
+ function useDerived(factory, dependencies, compareFn = equals) {
64
+ const deps = (0, import_react.useRef)(dependencies);
65
+ const valueRef = (0, import_react.useRef)({ value: null });
66
+ valueRef.current.value ??= factory();
67
+ if (deps.current.length !== dependencies.length || !deps.current.every((v, i) => compareFn(v, dependencies[i]))) {
68
+ valueRef.current.value = factory();
69
+ }
70
+ deps.current = dependencies;
71
+ return valueRef.current.value;
72
+ }
73
+
74
+ // src/idGenerator/useIdGenerator.ts
75
+ function useIdGenerator() {
76
+ const nextId = (0, import_react2.useRef)(0);
77
+ return useDerived(() => {
78
+ function generateId() {
79
+ return `${nextId.current++}`;
80
+ }
81
+ return wrapIdGenerator(generateId);
82
+ }, [nextId]);
83
+ }
84
+
85
+ // src/idGenerator/useProvidedIdGenerator.ts
86
+ var import_react4 = require("react");
87
+
88
+ // src/idGenerator/IdGeneratorContext.ts
89
+ var import_react3 = require("react");
90
+ var globalNextId = 0;
91
+ function globalGenerateId() {
92
+ return `${globalNextId++}`;
93
+ }
94
+ var IdGeneratorContext = (0, import_react3.createContext)(wrapIdGenerator(globalGenerateId));
95
+
96
+ // src/idGenerator/useProvidedIdGenerator.ts
97
+ function useProvidedIdGenerator() {
98
+ return (0, import_react4.useContext)(IdGeneratorContext);
99
+ }
100
+
101
+ // src/idGenerator/IdGeneratorProvider.ts
102
+ var IdGeneratorProvider = IdGeneratorContext.Provider;
103
+
104
+ // src/useMount.ts
105
+ var import_react5 = require("react");
106
+ function useMount(callback) {
107
+ return (0, import_react5.useEffect)(callback, []);
108
+ }
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ IdGeneratorProvider,
112
+ arrayWithIds,
113
+ arrayWithoutIds,
114
+ useDerived,
115
+ useIdGenerator,
116
+ useMount,
117
+ useProvidedIdGenerator,
118
+ withId,
119
+ withoutId,
120
+ wrapIdGenerator
121
+ });
122
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/idGenerator/generator.ts","../src/idGenerator/useIdGenerator.ts","../src/useDerived.ts","../src/idGenerator/useProvidedIdGenerator.ts","../src/idGenerator/IdGeneratorContext.ts","../src/idGenerator/IdGeneratorProvider.ts","../src/useMount.ts"],"sourcesContent":["export * from \"./idGenerator\"\nexport * from \"./useDerived\"\nexport * from \"./useMount\"\n","export type WithId<T extends object> = T extends object ? (T & { id: string }) : never\nexport type WithoutId<T extends object> = T extends object ? Omit<T, \"id\"> : never\n\nexport const withId = <T extends object>(v: T, id: string) =>\n ({ ...v, id }) as WithId<T>\nexport const withoutId = <T extends object>({ id, ...v }: WithId<T>) =>\n v as WithoutId<WithId<T>>\n\nexport type ArrayWithId<T extends object> = WithId<T>[]\nexport type ArrayWithoutId<T extends object> = WithoutId<WithId<T>>[]\n\nexport const arrayWithIds = <T extends object>(v: T[], idGenerator: () => string): ArrayWithId<T> =>\n v.map(i => withId(i, idGenerator()))\nexport const arrayWithoutIds = <T extends object>(v: ArrayWithId<T>): ArrayWithoutId<T> =>\n v.map(withoutId)\n\nexport function wrapIdGenerator(generator: () => string) {\n return Object.assign(generator, {\n withId<T extends {}>(v: T): WithId<T> {\n return withId(v, generator())\n },\n arrayWithIds<T extends {}>(v: T[]): ArrayWithId<T> {\n return arrayWithIds(v, generator)\n }\n })\n}\n\nexport type IdGenerator = ReturnType<typeof wrapIdGenerator>","import {useRef} from \"react\";\nimport {wrapIdGenerator, IdGenerator} from \"./generator\";\nimport {useDerived} from \"@/useDerived\";\n\nexport function useIdGenerator(): IdGenerator {\n const nextId = useRef(0)\n return useDerived(() => {\n function generateId() {\n return `${nextId.current++}`\n }\n return wrapIdGenerator(generateId)\n }, [nextId])\n}","import {DependencyList, useRef} from \"react\";\n\nfunction equals(x: unknown, y: unknown): boolean {\n if (typeof x === \"number\" && typeof y === \"number\") {\n return x === y || (x !== x && y !== y);\n }\n return x === y;\n}\n\nexport function useDerived<T>(\n factory: () => T,\n dependencies: DependencyList,\n compareFn: (a: unknown, b: unknown) => boolean = equals\n): T {\n const deps = useRef(dependencies)\n const valueRef = useRef<{ value: T | null }>({ value: null })\n\n valueRef.current.value ??= factory()\n\n if (deps.current.length !== dependencies.length || !deps.current.every((v, i) => compareFn(v, dependencies[i]))) {\n valueRef.current.value = factory()\n }\n\n deps.current = dependencies\n return valueRef.current.value\n}","import {useContext} from \"react\";\nimport {IdGenerator} from \"./generator\";\nimport {IdGeneratorContext} from \"./IdGeneratorContext\";\n\nexport function useProvidedIdGenerator(): IdGenerator {\n return useContext(IdGeneratorContext)\n}","import {createContext} from \"react\";\nimport {IdGenerator, wrapIdGenerator} from \"./generator\";\n\nlet globalNextId: number = 0\n\nfunction globalGenerateId(): string {\n return `${globalNextId++}`\n}\n\nexport const IdGeneratorContext = createContext<IdGenerator>(wrapIdGenerator(globalGenerateId))","import {IdGeneratorContext} from \"./IdGeneratorContext\"\n\nexport const IdGeneratorProvider = IdGeneratorContext.Provider","import {useEffect} from \"react\";\n\ntype CleanupFunction = () => void\nexport function useMount(callback: () => (CleanupFunction | void)) {\n return useEffect(callback, [])\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,SAAS,CAAmB,GAAM,QAC1C,EAAE,GAAG,GAAG,GAAG;AACT,IAAM,YAAY,CAAmB,EAAE,IAAI,GAAG,EAAE,MACnD;AAKG,IAAM,eAAe,CAAmB,GAAQ,gBACnD,EAAE,IAAI,OAAK,OAAO,GAAG,YAAY,CAAC,CAAC;AAChC,IAAM,kBAAkB,CAAmB,MAC9C,EAAE,IAAI,SAAS;AAEZ,SAAS,gBAAgB,WAAyB;AACrD,SAAO,OAAO,OAAO,WAAW;AAAA,IAC5B,OAAqB,GAAiB;AAClC,aAAO,OAAO,GAAG,UAAU,CAAC;AAAA,IAChC;AAAA,IACA,aAA2B,GAAwB;AAC/C,aAAO,aAAa,GAAG,SAAS;AAAA,IACpC;AAAA,EACJ,CAAC;AACL;;;ACzBA,IAAAA,gBAAqB;;;ACArB,mBAAqC;AAErC,SAAS,OAAO,GAAY,GAAqB;AAC7C,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;AAChD,WAAO,MAAM,KAAM,MAAM,KAAK,MAAM;AAAA,EACxC;AACA,SAAO,MAAM;AACjB;AAEO,SAAS,WACZ,SACA,cACA,YAAiD,QAChD;AACD,QAAM,WAAO,qBAAO,YAAY;AAChC,QAAM,eAAW,qBAA4B,EAAE,OAAO,KAAK,CAAC;AAE5D,WAAS,QAAQ,UAAU,QAAQ;AAEnC,MAAI,KAAK,QAAQ,WAAW,aAAa,UAAU,CAAC,KAAK,QAAQ,MAAM,CAAC,GAAG,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG;AAC7G,aAAS,QAAQ,QAAQ,QAAQ;AAAA,EACrC;AAEA,OAAK,UAAU;AACf,SAAO,SAAS,QAAQ;AAC5B;;;ADrBO,SAAS,iBAA8B;AAC1C,QAAM,aAAS,sBAAO,CAAC;AACvB,SAAO,WAAW,MAAM;AACpB,aAAS,aAAa;AAClB,aAAO,GAAG,OAAO,SAAS;AAAA,IAC9B;AACA,WAAO,gBAAgB,UAAU;AAAA,EACrC,GAAG,CAAC,MAAM,CAAC;AACf;;;AEZA,IAAAC,gBAAyB;;;ACAzB,IAAAC,gBAA4B;AAG5B,IAAI,eAAuB;AAE3B,SAAS,mBAA2B;AAChC,SAAO,GAAG,cAAc;AAC5B;AAEO,IAAM,yBAAqB,6BAA2B,gBAAgB,gBAAgB,CAAC;;;ADLvF,SAAS,yBAAsC;AAClD,aAAO,0BAAW,kBAAkB;AACxC;;;AEJO,IAAM,sBAAsB,mBAAmB;;;ACFtD,IAAAC,gBAAwB;AAGjB,SAAS,SAAS,UAA0C;AAC/D,aAAO,yBAAU,UAAU,CAAC,CAAC;AACjC;","names":["import_react","import_react","import_react","import_react"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,86 @@
1
+ // src/idGenerator/generator.ts
2
+ var withId = (v, id) => ({ ...v, id });
3
+ var withoutId = ({ id, ...v }) => v;
4
+ var arrayWithIds = (v, idGenerator) => v.map((i) => withId(i, idGenerator()));
5
+ var arrayWithoutIds = (v) => v.map(withoutId);
6
+ function wrapIdGenerator(generator) {
7
+ return Object.assign(generator, {
8
+ withId(v) {
9
+ return withId(v, generator());
10
+ },
11
+ arrayWithIds(v) {
12
+ return arrayWithIds(v, generator);
13
+ }
14
+ });
15
+ }
16
+
17
+ // src/idGenerator/useIdGenerator.ts
18
+ import { useRef as useRef2 } from "react";
19
+
20
+ // src/useDerived.ts
21
+ import { useRef } from "react";
22
+ function equals(x, y) {
23
+ if (typeof x === "number" && typeof y === "number") {
24
+ return x === y || x !== x && y !== y;
25
+ }
26
+ return x === y;
27
+ }
28
+ function useDerived(factory, dependencies, compareFn = equals) {
29
+ const deps = useRef(dependencies);
30
+ const valueRef = useRef({ value: null });
31
+ valueRef.current.value ??= factory();
32
+ if (deps.current.length !== dependencies.length || !deps.current.every((v, i) => compareFn(v, dependencies[i]))) {
33
+ valueRef.current.value = factory();
34
+ }
35
+ deps.current = dependencies;
36
+ return valueRef.current.value;
37
+ }
38
+
39
+ // src/idGenerator/useIdGenerator.ts
40
+ function useIdGenerator() {
41
+ const nextId = useRef2(0);
42
+ return useDerived(() => {
43
+ function generateId() {
44
+ return `${nextId.current++}`;
45
+ }
46
+ return wrapIdGenerator(generateId);
47
+ }, [nextId]);
48
+ }
49
+
50
+ // src/idGenerator/useProvidedIdGenerator.ts
51
+ import { useContext } from "react";
52
+
53
+ // src/idGenerator/IdGeneratorContext.ts
54
+ import { createContext } from "react";
55
+ var globalNextId = 0;
56
+ function globalGenerateId() {
57
+ return `${globalNextId++}`;
58
+ }
59
+ var IdGeneratorContext = createContext(wrapIdGenerator(globalGenerateId));
60
+
61
+ // src/idGenerator/useProvidedIdGenerator.ts
62
+ function useProvidedIdGenerator() {
63
+ return useContext(IdGeneratorContext);
64
+ }
65
+
66
+ // src/idGenerator/IdGeneratorProvider.ts
67
+ var IdGeneratorProvider = IdGeneratorContext.Provider;
68
+
69
+ // src/useMount.ts
70
+ import { useEffect } from "react";
71
+ function useMount(callback) {
72
+ return useEffect(callback, []);
73
+ }
74
+ export {
75
+ IdGeneratorProvider,
76
+ arrayWithIds,
77
+ arrayWithoutIds,
78
+ useDerived,
79
+ useIdGenerator,
80
+ useMount,
81
+ useProvidedIdGenerator,
82
+ withId,
83
+ withoutId,
84
+ wrapIdGenerator
85
+ };
86
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/idGenerator/generator.ts","../src/idGenerator/useIdGenerator.ts","../src/useDerived.ts","../src/idGenerator/useProvidedIdGenerator.ts","../src/idGenerator/IdGeneratorContext.ts","../src/idGenerator/IdGeneratorProvider.ts","../src/useMount.ts"],"sourcesContent":["export type WithId<T extends object> = T extends object ? (T & { id: string }) : never\nexport type WithoutId<T extends object> = T extends object ? Omit<T, \"id\"> : never\n\nexport const withId = <T extends object>(v: T, id: string) =>\n ({ ...v, id }) as WithId<T>\nexport const withoutId = <T extends object>({ id, ...v }: WithId<T>) =>\n v as WithoutId<WithId<T>>\n\nexport type ArrayWithId<T extends object> = WithId<T>[]\nexport type ArrayWithoutId<T extends object> = WithoutId<WithId<T>>[]\n\nexport const arrayWithIds = <T extends object>(v: T[], idGenerator: () => string): ArrayWithId<T> =>\n v.map(i => withId(i, idGenerator()))\nexport const arrayWithoutIds = <T extends object>(v: ArrayWithId<T>): ArrayWithoutId<T> =>\n v.map(withoutId)\n\nexport function wrapIdGenerator(generator: () => string) {\n return Object.assign(generator, {\n withId<T extends {}>(v: T): WithId<T> {\n return withId(v, generator())\n },\n arrayWithIds<T extends {}>(v: T[]): ArrayWithId<T> {\n return arrayWithIds(v, generator)\n }\n })\n}\n\nexport type IdGenerator = ReturnType<typeof wrapIdGenerator>","import {useRef} from \"react\";\nimport {wrapIdGenerator, IdGenerator} from \"./generator\";\nimport {useDerived} from \"@/useDerived\";\n\nexport function useIdGenerator(): IdGenerator {\n const nextId = useRef(0)\n return useDerived(() => {\n function generateId() {\n return `${nextId.current++}`\n }\n return wrapIdGenerator(generateId)\n }, [nextId])\n}","import {DependencyList, useRef} from \"react\";\n\nfunction equals(x: unknown, y: unknown): boolean {\n if (typeof x === \"number\" && typeof y === \"number\") {\n return x === y || (x !== x && y !== y);\n }\n return x === y;\n}\n\nexport function useDerived<T>(\n factory: () => T,\n dependencies: DependencyList,\n compareFn: (a: unknown, b: unknown) => boolean = equals\n): T {\n const deps = useRef(dependencies)\n const valueRef = useRef<{ value: T | null }>({ value: null })\n\n valueRef.current.value ??= factory()\n\n if (deps.current.length !== dependencies.length || !deps.current.every((v, i) => compareFn(v, dependencies[i]))) {\n valueRef.current.value = factory()\n }\n\n deps.current = dependencies\n return valueRef.current.value\n}","import {useContext} from \"react\";\nimport {IdGenerator} from \"./generator\";\nimport {IdGeneratorContext} from \"./IdGeneratorContext\";\n\nexport function useProvidedIdGenerator(): IdGenerator {\n return useContext(IdGeneratorContext)\n}","import {createContext} from \"react\";\nimport {IdGenerator, wrapIdGenerator} from \"./generator\";\n\nlet globalNextId: number = 0\n\nfunction globalGenerateId(): string {\n return `${globalNextId++}`\n}\n\nexport const IdGeneratorContext = createContext<IdGenerator>(wrapIdGenerator(globalGenerateId))","import {IdGeneratorContext} from \"./IdGeneratorContext\"\n\nexport const IdGeneratorProvider = IdGeneratorContext.Provider","import {useEffect} from \"react\";\n\ntype CleanupFunction = () => void\nexport function useMount(callback: () => (CleanupFunction | void)) {\n return useEffect(callback, [])\n}"],"mappings":";AAGO,IAAM,SAAS,CAAmB,GAAM,QAC1C,EAAE,GAAG,GAAG,GAAG;AACT,IAAM,YAAY,CAAmB,EAAE,IAAI,GAAG,EAAE,MACnD;AAKG,IAAM,eAAe,CAAmB,GAAQ,gBACnD,EAAE,IAAI,OAAK,OAAO,GAAG,YAAY,CAAC,CAAC;AAChC,IAAM,kBAAkB,CAAmB,MAC9C,EAAE,IAAI,SAAS;AAEZ,SAAS,gBAAgB,WAAyB;AACrD,SAAO,OAAO,OAAO,WAAW;AAAA,IAC5B,OAAqB,GAAiB;AAClC,aAAO,OAAO,GAAG,UAAU,CAAC;AAAA,IAChC;AAAA,IACA,aAA2B,GAAwB;AAC/C,aAAO,aAAa,GAAG,SAAS;AAAA,IACpC;AAAA,EACJ,CAAC;AACL;;;ACzBA,SAAQ,UAAAA,eAAa;;;ACArB,SAAwB,cAAa;AAErC,SAAS,OAAO,GAAY,GAAqB;AAC7C,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;AAChD,WAAO,MAAM,KAAM,MAAM,KAAK,MAAM;AAAA,EACxC;AACA,SAAO,MAAM;AACjB;AAEO,SAAS,WACZ,SACA,cACA,YAAiD,QAChD;AACD,QAAM,OAAO,OAAO,YAAY;AAChC,QAAM,WAAW,OAA4B,EAAE,OAAO,KAAK,CAAC;AAE5D,WAAS,QAAQ,UAAU,QAAQ;AAEnC,MAAI,KAAK,QAAQ,WAAW,aAAa,UAAU,CAAC,KAAK,QAAQ,MAAM,CAAC,GAAG,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG;AAC7G,aAAS,QAAQ,QAAQ,QAAQ;AAAA,EACrC;AAEA,OAAK,UAAU;AACf,SAAO,SAAS,QAAQ;AAC5B;;;ADrBO,SAAS,iBAA8B;AAC1C,QAAM,SAASC,QAAO,CAAC;AACvB,SAAO,WAAW,MAAM;AACpB,aAAS,aAAa;AAClB,aAAO,GAAG,OAAO,SAAS;AAAA,IAC9B;AACA,WAAO,gBAAgB,UAAU;AAAA,EACrC,GAAG,CAAC,MAAM,CAAC;AACf;;;AEZA,SAAQ,kBAAiB;;;ACAzB,SAAQ,qBAAoB;AAG5B,IAAI,eAAuB;AAE3B,SAAS,mBAA2B;AAChC,SAAO,GAAG,cAAc;AAC5B;AAEO,IAAM,qBAAqB,cAA2B,gBAAgB,gBAAgB,CAAC;;;ADLvF,SAAS,yBAAsC;AAClD,SAAO,WAAW,kBAAkB;AACxC;;;AEJO,IAAM,sBAAsB,mBAAmB;;;ACFtD,SAAQ,iBAAgB;AAGjB,SAAS,SAAS,UAA0C;AAC/D,SAAO,UAAU,UAAU,CAAC,CAAC;AACjC;","names":["useRef","useRef"]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@gamedev-sensei/react-extras",
3
+ "repository": "git@github.com:gamedev-sensei/package-extras.git",
4
+ "version": "1.1.1",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "/dist"
11
+ ],
12
+ "exports": {
13
+ "import": {
14
+ "types": "./dist/index.d.mts",
15
+ "import": "./dist/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.ts",
19
+ "require": "./dist/index.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "type-check": "tsc --noEmit",
24
+ "build": "tsup && attw --pack ."
25
+ },
26
+ "dependencies": {
27
+ "@arethetypeswrong/cli": "^0.18.2",
28
+ "react": "^19.1.0",
29
+ "react-dom": "^19.1.0",
30
+ "remeda": "^2.23.3"
31
+ },
32
+ "devDependencies": {
33
+ "@gamedev-sensei/ts-config": "1.1.1",
34
+ "@gamedev-sensei/tsup-config": "1.1.1",
35
+ "@types/react": "^19.1.8",
36
+ "@types/react-dom": "^19.1.6",
37
+ "tsup": "patch:tsup@npm%3A8.5.0#~/.yarn/patches/tsup-npm-8.5.0-e9d25b74d7.patch"
38
+ }
39
+ }