totally-tubular 0.5.0 → 0.6.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/dist/react.d.ts CHANGED
@@ -32,7 +32,7 @@ import type { AllObjectKeys, PropType } from './types.js';
32
32
  * }
33
33
  * ```
34
34
  */
35
- export declare function useTubular<T extends object, K extends string>(tubular: Tubular<T>, key: K & AllObjectKeys<T>): readonly [PropType<T, K> | null, (newValOrCallback: PropType<T, K> | ((prevVal: PropType<T, K> | null) => PropType<T, K>)) => void];
35
+ export declare function useTubular<T extends object, K extends AllObjectKeys<T>>(tubular: Tubular<T>, key: K): readonly [PropType<T, K> | null, (newValOrCallback: PropType<T, K> | ((prevVal: PropType<T, K> | null) => PropType<T, K>)) => void];
36
36
  /**
37
37
  * Creates a hook bound to a specific {@link Tubular} instance, so you never
38
38
  * have to pass the instance around at every call site.
@@ -63,7 +63,7 @@ export declare function useTubular<T extends object, K extends string>(tubular:
63
63
  * }
64
64
  * ```
65
65
  */
66
- export declare function createUseTubular<T extends object>(tubular: Tubular<T>): <K extends string>(key: K & AllObjectKeys<T>) => readonly [PropType<T, K & AllObjectKeys<T>> | null, (newValOrCallback: PropType<T, K & AllObjectKeys<T>> | ((prevVal: PropType<T, K & AllObjectKeys<T>> | null) => PropType<T, K & AllObjectKeys<T>>)) => void];
66
+ export declare function createUseTubular<T extends object>(tubular: Tubular<T>): <K extends AllObjectKeys<T>>(key: K) => readonly [PropType<T, K> | null, (newValOrCallback: PropType<T, K> | ((prevVal: PropType<T, K> | null) => PropType<T, K>)) => void];
67
67
  /**
68
68
  * A React hook that returns a stable callback to reset a {@link Tubular} store
69
69
  * back to its initial state.
@@ -15,11 +15,11 @@ export declare class Tubular<T extends object> {
15
15
  /**
16
16
  * observe changes to some part of state that was updated
17
17
  */
18
- observe<K extends string>(propPath: K & AllObjectKeys<T>, observeCallback: ObservationCallback<T>): void;
18
+ observe<K extends AllObjectKeys<T>>(propPath: K, observeCallback: ObservationCallback<T, K>): void;
19
19
  /**
20
20
  * reads a portion of your state
21
21
  */
22
- read<K extends string>(readPath: K & AllObjectKeys<T>): PropType<T, K> | null;
22
+ read<K extends AllObjectKeys<T>>(readPath: K): PropType<T, K> | null;
23
23
  private resetImpl;
24
24
  /**
25
25
  * resets the state back to its initial value
@@ -29,9 +29,9 @@ export declare class Tubular<T extends object> {
29
29
  /**
30
30
  * disconnects an observer callback from totally tubular
31
31
  */
32
- unobserve<K extends string>(propPath: K & AllObjectKeys<T>, observeCallback: ObservationCallback<T>): void;
32
+ unobserve<K extends AllObjectKeys<T>>(propPath: K, observeCallback: ObservationCallback<T, K>): void;
33
33
  /**
34
34
  * updates a portion of your state
35
35
  */
36
- update<K extends string>(updatePath: K & AllObjectKeys<T>, valUpdater: (oldVal: PropType<T, K>) => PropType<T, K>): void;
36
+ update<K extends AllObjectKeys<T>>(updatePath: K, valUpdater: (oldVal: PropType<T, K>) => PropType<T, K>): void;
37
37
  }
package/dist/types.d.ts CHANGED
@@ -41,13 +41,13 @@ export type PropType<T, P extends string> = P extends keyof T ? T[P] : P extends
41
41
  /**
42
42
  * Callback invoked by Tubular whenever an observed path changes.
43
43
  *
44
- * The previous definition used defaulted type parameters
45
- * (`K = AllObjectKeys<T>`, `V = PropType<T, K & string>`). Default type
46
- * parameters are eagerly evaluated by the checker at *every* reference to
47
- * `ObservationCallback<T>`, causing a full `AllObjectKeys<T>` + distributed
48
- * `PropType` expansion each time. Using `unknown` for the value parameters
49
- * defers any narrowing to call sites that actually need it, which is a far
50
- * smaller surface area.
44
+ * `K` is the dot-path being observed, and `newVal`/`oldVal` resolve to
45
+ * `PropType<T, K>` — the value type of exactly that path. `K` is a required
46
+ * type parameter with no default: defaulted parameters were eagerly expanded
47
+ * at *every* reference to `ObservationCallback<T>` (a full `AllObjectKeys<T>`
48
+ * + distributed `PropType` expansion each time). This form evaluates
49
+ * `PropType` once per call site, against the concrete literal key that
50
+ * `observe`/`unobserve` infer from the path argument.
51
51
  */
52
- export type ObservationCallback<T> = (newVal: unknown, oldVal: unknown, propPath: AllObjectKeys<T>) => void;
52
+ export type ObservationCallback<T, K extends string> = (newVal: PropType<T, K>, oldVal: PropType<T, K>, propPath: K) => void;
53
53
  export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A completely framework-agnostic, JavaScript / TypeScript state management and update broadcasting library wit zero dependencies, solid performance and a micro file size.",
4
4
  "name": "totally-tubular",
5
5
  "type": "module",
6
- "version": "0.5.0",
6
+ "version": "0.6.0",
7
7
  "keywords": [
8
8
  "state",
9
9
  "management",
@@ -26,6 +26,13 @@
26
26
  "files": [
27
27
  "dist/"
28
28
  ],
29
+ "scripts": {
30
+ "build": "rm -rf dist/ && tsc --project ./tsconfig.build.json",
31
+ "clean": "rm -rf dist/",
32
+ "test": "vitest test",
33
+ "test:performance": "tsx ./performanceTests.ts",
34
+ "test:watch": "vitest test --watch"
35
+ },
29
36
  "devDependencies": {
30
37
  "@better-builds/lets-version": "^1.6.0",
31
38
  "@biomejs/biome": "^2.4.16",
@@ -71,12 +78,5 @@
71
78
  "default": "./dist/types.js"
72
79
  },
73
80
  "./package.json": "./package.json"
74
- },
75
- "scripts": {
76
- "build": "rm -rf dist/ && tsc --project ./tsconfig.build.json",
77
- "clean": "rm -rf dist/",
78
- "test": "vitest test",
79
- "test:performance": "tsx ./performanceTests.ts",
80
- "test:watch": "vitest test --watch"
81
81
  }
82
- }
82
+ }