@tomorrowevening/theatre-dataverse 1.0.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.
Files changed (46) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +709 -0
  3. package/dist/Atom.d.ts +127 -0
  4. package/dist/Atom.d.ts.map +1 -0
  5. package/dist/PointerProxy.d.ts +33 -0
  6. package/dist/PointerProxy.d.ts.map +1 -0
  7. package/dist/Ticker.d.ts +105 -0
  8. package/dist/Ticker.d.ts.map +1 -0
  9. package/dist/atom.typeTest.d.ts +2 -0
  10. package/dist/atom.typeTest.d.ts.map +1 -0
  11. package/dist/index.d.ts +19 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +1555 -0
  14. package/dist/index.js.map +7 -0
  15. package/dist/pointer.d.ts +107 -0
  16. package/dist/pointer.d.ts.map +1 -0
  17. package/dist/pointer.typeTest.d.ts +2 -0
  18. package/dist/pointer.typeTest.d.ts.map +1 -0
  19. package/dist/pointerToPrism.d.ts +20 -0
  20. package/dist/pointerToPrism.d.ts.map +1 -0
  21. package/dist/prism/Interface.d.ts +33 -0
  22. package/dist/prism/Interface.d.ts.map +1 -0
  23. package/dist/prism/asyncIterateOver.d.ts +1 -0
  24. package/dist/prism/asyncIterateOver.d.ts.map +1 -0
  25. package/dist/prism/discoveryMechanism.d.ts +4 -0
  26. package/dist/prism/discoveryMechanism.d.ts.map +1 -0
  27. package/dist/prism/iterateAndCountTicks.d.ts +7 -0
  28. package/dist/prism/iterateAndCountTicks.d.ts.map +1 -0
  29. package/dist/prism/iterateOver.d.ts +4 -0
  30. package/dist/prism/iterateOver.d.ts.map +1 -0
  31. package/dist/prism/prism.d.ts +175 -0
  32. package/dist/prism/prism.d.ts.map +1 -0
  33. package/dist/setupTestEnv.d.ts +2 -0
  34. package/dist/setupTestEnv.d.ts.map +1 -0
  35. package/dist/tsdoc-metadata.json +11 -0
  36. package/dist/types.d.ts +6 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/utils/Stack.d.ts +16 -0
  39. package/dist/utils/Stack.d.ts.map +1 -0
  40. package/dist/utils/typeTestUtils.d.ts +11 -0
  41. package/dist/utils/typeTestUtils.d.ts.map +1 -0
  42. package/dist/utils/updateDeep.d.ts +3 -0
  43. package/dist/utils/updateDeep.d.ts.map +1 -0
  44. package/dist/val.d.ts +14 -0
  45. package/dist/val.d.ts.map +1 -0
  46. package/package.json +50 -0
@@ -0,0 +1,175 @@
1
+ import type { $IntentionalAny, VoidFn } from '../types';
2
+ import type { Prism } from './Interface';
3
+ type IRef<T> = {
4
+ current: T;
5
+ };
6
+ /**
7
+ * Just like React's `useRef()`, `prism.ref()` allows us to create a prism that holds a reference to some value.
8
+ * The only difference is that `prism.ref()` requires a key to be passed into it, whlie `useRef()` doesn't.
9
+ * This means that we can call `prism.ref()` in any order, and we can call it multiple times with the same key.
10
+ * @param key - The key for the ref. Should be unique inside of the prism.
11
+ * @param initialValue - The initial value for the ref.
12
+ * @returns `{current: V}` - The ref object.
13
+ *
14
+ * Note that the ref object will always return its initial value if the prism is cold. It'll only record
15
+ * its current value if the prism is hot (and will forget again if the prism goes cold again).
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const pr = prism(() => {
20
+ * const ref1 = prism.ref("ref1", 0)
21
+ * console.log(ref1.current) // will print 0, and if the prism is hot, it'll print the current value
22
+ * ref1.current++ // changing the current value of the ref
23
+ * })
24
+ * ```
25
+ */
26
+ declare function ref<T>(key: string, initialValue: T): IRef<T>;
27
+ /**
28
+ * An effect hook, similar to React's `useEffect()`, but is not sensitive to call order by using `key`.
29
+ *
30
+ * @param key - the key for the effect. Should be uniqe inside of the prism.
31
+ * @param cb - the callback function. Requires returning a cleanup function.
32
+ * @param deps - the dependency array
33
+ */
34
+ declare function effect(key: string, cb: () => () => void, deps?: unknown[]): void;
35
+ /**
36
+ * `prism.memo()` works just like React's `useMemo()` hook. It's a way to cache the result of a function call.
37
+ * The only difference is that `prism.memo()` requires a key to be passed into it, whlie `useMemo()` doesn't.
38
+ * This means that we can call `prism.memo()` in any order, and we can call it multiple times with the same key.
39
+ *
40
+ * @param key - The key for the memo. Should be unique inside of the prism
41
+ * @param fn - The function to memoize
42
+ * @param deps - The dependency array. Provide `[]` if you want to the value to be memoized only once and never re-calculated.
43
+ * @returns The result of the function call
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const pr = prism(() => {
48
+ * const memoizedReturnValueOfExpensiveFn = prism.memo("memo1", expensiveFn, [])
49
+ * })
50
+ * ```
51
+ */
52
+ declare function memo<T>(key: string, fn: () => T, deps: undefined | $IntentionalAny[] | ReadonlyArray<$IntentionalAny>): T;
53
+ /**
54
+ * A state hook, similar to react's `useState()`.
55
+ *
56
+ * @param key - the key for the state
57
+ * @param initialValue - the initial value
58
+ * @returns [currentState, setState]
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import {prism} from 'dataverse'
63
+ *
64
+ * // This prism holds the current mouse position and updates when the mouse moves
65
+ * const mousePositionD = prism(() => {
66
+ * const [pos, setPos] = prism.state<[x: number, y: number]>('pos', [0, 0])
67
+ *
68
+ * prism.effect(
69
+ * 'setupListeners',
70
+ * () => {
71
+ * const handleMouseMove = (e: MouseEvent) => {
72
+ * setPos([e.screenX, e.screenY])
73
+ * }
74
+ * document.addEventListener('mousemove', handleMouseMove)
75
+ *
76
+ * return () => {
77
+ * document.removeEventListener('mousemove', handleMouseMove)
78
+ * }
79
+ * },
80
+ * [],
81
+ * )
82
+ *
83
+ * return pos
84
+ * })
85
+ * ```
86
+ */
87
+ declare function state<T>(key: string, initialValue: T): [T, (val: T) => void];
88
+ /**
89
+ * This is useful to make sure your code is running inside a `prism()` call.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import {prism} from '@tomorrowevening/theatre-dataverse'
94
+ *
95
+ * function onlyUsefulInAPrism() {
96
+ * prism.ensurePrism()
97
+ * }
98
+ *
99
+ * prism(() => {
100
+ * onlyUsefulInAPrism() // will run fine
101
+ * })
102
+ *
103
+ * setTimeout(() => {
104
+ * onlyUsefulInAPrism() // throws an error
105
+ * console.log('This will never get logged')
106
+ * }, 0)
107
+ * ```
108
+ */
109
+ declare function ensurePrism(): void;
110
+ declare function scope<T>(key: string, fn: () => T): T;
111
+ /**
112
+ * Just an alias for `prism.memo(key, () => prism(fn), deps).getValue()`. It creates a new prism, memoizes it, and returns the value.
113
+ * `prism.sub()` is useful when you want to divide your prism into smaller prisms, each of which
114
+ * would _only_ recalculate when _certain_ dependencies change. In other words, it's an optimization tool.
115
+ *
116
+ * @param key - The key for the memo. Should be unique inside of the prism
117
+ * @param fn - The function to run inside the prism
118
+ * @param deps - The dependency array. Provide `[]` if you want to the value to be memoized only once and never re-calculated.
119
+ * @returns The value of the inner prism
120
+ */
121
+ declare function sub<T>(key: string, fn: () => T, deps: undefined | $IntentionalAny[]): T;
122
+ /**
123
+ * @returns true if the current function is running inside a `prism()` call.
124
+ */
125
+ declare function inPrism(): boolean;
126
+ /**
127
+ * `prism.source()` allow a prism to react to changes in some external source (other than other prisms).
128
+ * For example, `Atom.pointerToPrism()` uses `prism.source()` to create a prism that reacts to changes in the atom's value.
129
+
130
+ * @param subscribe - The prism will call this function as soon as the prism goes hot. This function should return an unsubscribe function function which the prism will call when it goes cold.
131
+ * @param getValue - A function that returns the current value of the external source.
132
+ * @returns The current value of the source
133
+ *
134
+ * Example:
135
+ * ```ts
136
+ * function prismFromInputElement(input: HTMLInputElement): Prism<string> {
137
+ * function listen(cb: (value: string) => void) {
138
+ * const listener = () => {
139
+ * cb(input.value)
140
+ * }
141
+ * input.addEventListener('input', listener)
142
+ * return () => {
143
+ * input.removeEventListener('input', listener)
144
+ * }
145
+ * }
146
+ *
147
+ * function get() {
148
+ * return input.value
149
+ * }
150
+ * return prism(() => prism.source(listen, get))
151
+ * }
152
+ * ```
153
+ */
154
+ declare function source<V>(subscribe: (fn: (val: V) => void) => VoidFn, getValue: () => V): V;
155
+ type IPrismFn = {
156
+ <T>(fn: () => T): Prism<T>;
157
+ ref: typeof ref;
158
+ effect: typeof effect;
159
+ memo: typeof memo;
160
+ ensurePrism: typeof ensurePrism;
161
+ state: typeof state;
162
+ scope: typeof scope;
163
+ sub: typeof sub;
164
+ inPrism: typeof inPrism;
165
+ source: typeof source;
166
+ };
167
+ /**
168
+ * Creates a prism from the passed function that adds all prisms referenced
169
+ * in it as dependencies, and reruns the function when these change.
170
+ *
171
+ * @param fn - The function to rerun when the prisms referenced in it change.
172
+ */
173
+ declare const prism: IPrismFn;
174
+ export default prism;
175
+ //# sourceMappingURL=prism.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prism.d.ts","sourceRoot":"","sources":["../../src/prism/prism.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,eAAe,EAAE,MAAM,EAAC,MAAM,UAAU,CAAA;AAErD,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAmiBtC,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,OAAO,EAAE,CAAC,CAAA;CACX,CAAA;AAYD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAOrD;AAED;;;;;;GAMG;AACH,iBAAS,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,MAAM,IAAI,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAOzE;AAoBD;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,IAAI,CAAC,CAAC,EACb,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,CAAC,EACX,IAAI,EAAE,SAAS,GAAG,eAAe,EAAE,GAAG,aAAa,CAAC,eAAe,CAAC,GACnE,CAAC,CAOH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,iBAAS,KAAK,CAAC,CAA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,KAAK,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=setupTestEnv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupTestEnv.d.ts","sourceRoot":"","sources":["../src/setupTestEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.36.4"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,6 @@
1
+ /** For `any`s that aren't meant to stay `any`*/
2
+ export type $FixMe = any;
3
+ /** For `any`s that we don't care about */
4
+ export type $IntentionalAny = any;
5
+ export type VoidFn = () => void;
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,MAAM,MAAM,GAAG,GAAG,CAAA;AACxB,0CAA0C;AAC1C,MAAM,MAAM,eAAe,GAAG,GAAG,CAAA;AAEjC,MAAM,MAAM,MAAM,GAAG,MAAM,IAAI,CAAA"}
@@ -0,0 +1,16 @@
1
+ interface Node<Data> {
2
+ next: undefined | Node<Data>;
3
+ data: Data;
4
+ }
5
+ /**
6
+ * Just a simple LinkedList
7
+ */
8
+ export default class Stack<Data> {
9
+ _head: undefined | Node<Data>;
10
+ constructor();
11
+ peek(): Data | undefined;
12
+ pop(): Data | undefined;
13
+ push(data: Data): void;
14
+ }
15
+ export {};
16
+ //# sourceMappingURL=Stack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stack.d.ts","sourceRoot":"","sources":["../../src/utils/Stack.ts"],"names":[],"mappings":"AAAA,UAAU,IAAI,CAAC,IAAI;IACjB,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5B,IAAI,EAAE,IAAI,CAAA;CACX;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK,CAAC,IAAI;IAC7B,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;;IAM7B,IAAI;IAIJ,GAAG;IASH,IAAI,CAAC,IAAI,EAAE,IAAI;CAIhB"}
@@ -0,0 +1,11 @@
1
+ import type { $IntentionalAny } from '../types';
2
+ /**
3
+ * Useful in type tests, such as: const a: SomeType = _any
4
+ */
5
+ export declare const _any: $IntentionalAny;
6
+ /**
7
+ * Useful in typeTests. If you want to ensure that value v follows type V,
8
+ * just write `expectType<V>(v)`
9
+ */
10
+ export declare const expectType: <T extends unknown>(v: T) => T;
11
+ //# sourceMappingURL=typeTestUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeTestUtils.d.ts","sourceRoot":"","sources":["../../src/utils/typeTestUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,UAAU,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,eAAsB,CAAA;AAEzC;;;GAGG;AACH,eAAO,MAAM,UAAU,gCAAoC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { $IntentionalAny } from '../types';
2
+ export default function updateDeep<S>(state: S, path: (string | number | undefined)[], reducer: (...args: $IntentionalAny[]) => $IntentionalAny): S;
3
+ //# sourceMappingURL=updateDeep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateDeep.d.ts","sourceRoot":"","sources":["../../src/utils/updateDeep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,eAAe,EAAC,MAAM,UAAU,CAAA;AAErD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,EAClC,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,EAAE,EACrC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,eAAe,EAAE,KAAK,eAAe,GACvD,CAAC,CAGH"}
package/dist/val.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Prism } from './prism/Interface';
2
+ import type { PointerType } from './pointer';
3
+ /**
4
+ * Convenience function that returns a plain value from its argument, whether it
5
+ * is a pointer, a prism or a plain value itself.
6
+ *
7
+ * @remarks
8
+ * For pointers, the value is returned by first creating a prism, so it is
9
+ * reactive e.g. when used in a `prism`.
10
+ *
11
+ * @param input - The argument to return a value from.
12
+ */
13
+ export declare const val: <P extends PointerType<any> | Prism<any> | null | undefined>(input: P) => P extends PointerType<infer T> ? T : P extends Prism<infer T_1> ? T_1 : P extends null | undefined ? P : unknown;
14
+ //# sourceMappingURL=val.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"val.d.ts","sourceRoot":"","sources":["../src/val.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAA;AAE5C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AAK1C;;;;;;;;;GASG;AAEH,eAAO,MAAM,GAAG,4LAsBf,CAAA"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@tomorrowevening/theatre-dataverse",
3
+ "version": "1.0.0",
4
+ "license": "Apache-2.0",
5
+ "author": {
6
+ "name": "Colin Duffy",
7
+ "email": "colin@tomorrowevening.com",
8
+ "url": "https://tomorrowevening.com/"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/tomorrowevening/theatre",
13
+ "directory": "packages/dataverse"
14
+ },
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "files": [
18
+ "dist/**/*"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "prepack": "node ../../devEnv/ensurePublishing.js",
25
+ "typecheck": "yarn run build:ts",
26
+ "build": "run-s build:ts build:js build:api-json",
27
+ "build:ts": "tsc --build ./tsconfig.json",
28
+ "build:js": "tsx ./devEnv/build.ts",
29
+ "build:api-json": "api-extractor run --local --config devEnv/api-extractor.json",
30
+ "prepublish": "node ../../devEnv/ensurePublishing.js",
31
+ "clean": "rm -rf ./dist && rm -f tsconfig.tsbuildinfo",
32
+ "docs": "typedoc src/index.ts --out api --plugin typedoc-plugin-markdown --readme none",
33
+ "precommit": "yarn run docs"
34
+ },
35
+ "devDependencies": {
36
+ "@microsoft/api-extractor": "^7.36.4",
37
+ "@types/jest": "^26.0.23",
38
+ "@types/lodash-es": "^4.17.4",
39
+ "@types/node": "^15.6.2",
40
+ "esbuild": "^0.12.15",
41
+ "npm-run-all": "^4.1.5",
42
+ "tsx": "4.7.0",
43
+ "typedoc": "^0.24.8",
44
+ "typedoc-plugin-markdown": "^3.15.4",
45
+ "typescript": "5.1.6"
46
+ },
47
+ "dependencies": {
48
+ "lodash-es": "^4.17.21"
49
+ }
50
+ }