humn 1.4.1 → 1.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/cortex.d.ts +101 -0
- package/dist/css.d.ts +8 -0
- package/dist/h.d.ts +7 -0
- package/dist/humn.js +615 -193
- package/dist/humn.js.map +1 -1
- package/dist/humn.umd.js +3 -3
- package/dist/humn.umd.js.map +1 -1
- package/dist/index.d.ts +6 -156
- package/dist/lifecycle.d.ts +10 -0
- package/dist/mount.d.ts +1 -0
- package/dist/observer.d.ts +5 -0
- package/dist/persist.d.ts +12 -0
- package/dist/runtime/component-lifecycle.d.ts +8 -0
- package/dist/runtime/create-element.d.ts +2 -0
- package/dist/runtime/element-runtime.d.ts +1 -0
- package/dist/runtime/event-listeners.d.ts +12 -0
- package/dist/runtime/interaction-helpers.d.ts +10 -0
- package/dist/runtime/patch-props.d.ts +1 -0
- package/dist/runtime/patch.d.ts +16 -0
- package/dist/runtime/reconcile-children.d.ts +8 -0
- package/package.json +5 -8
package/dist/cortex.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapped type for the Memory configuration object.
|
|
3
|
+
* Allows each property to be the raw value OR a persisted wrapper.
|
|
4
|
+
* @template T
|
|
5
|
+
* @typedef { { [K in keyof T]: T[K] | import('./persist.js').Persisted<T[K]> } } MemoryInput
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Deeply unwraps persisted values from the memory shape.
|
|
9
|
+
* @template {object} T
|
|
10
|
+
* @typedef {{ [K in keyof T]: T[K] extends import('./persist.js').Persisted<infer I> ? I : T[K] }} UnwrappedMemory
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @template T
|
|
14
|
+
* @callback Getter
|
|
15
|
+
* @returns {T}
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @template T
|
|
19
|
+
* @callback Setter
|
|
20
|
+
* @param {Partial<T> | ((state: T) => void | Partial<T> | unknown)} updater
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @template M, S
|
|
25
|
+
* @callback SynapsesBuilder
|
|
26
|
+
* @param {Setter<M>} set
|
|
27
|
+
* @param {Getter<M>} get
|
|
28
|
+
* @returns {S}
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @template M, S
|
|
32
|
+
* @typedef {object} CortexConfig
|
|
33
|
+
* @property {MemoryInput<M>} memory - The initial state configuration
|
|
34
|
+
* @property {SynapsesBuilder<M, S>} synapses - The synapses builder function
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* The Cortex class manages the state of the application.
|
|
38
|
+
*
|
|
39
|
+
* @template {object} MemoryType The shape of the application state
|
|
40
|
+
* @template {object} SynapsesType The shape of the actions/methods
|
|
41
|
+
*/
|
|
42
|
+
export class Cortex<MemoryType extends unknown, SynapsesType extends unknown> {
|
|
43
|
+
/**
|
|
44
|
+
* Creates an instance of Cortex.
|
|
45
|
+
* @param {CortexConfig<MemoryType, SynapsesType>} config
|
|
46
|
+
*/
|
|
47
|
+
constructor({ memory, synapses }: CortexConfig<MemoryType, SynapsesType>);
|
|
48
|
+
_persistenceMap: Map<any, any>;
|
|
49
|
+
/** @type {UnwrappedMemory<MemoryType>} */
|
|
50
|
+
_memory: UnwrappedMemory<MemoryType>;
|
|
51
|
+
_listeners: Map<any, any>;
|
|
52
|
+
/** @type {SynapsesType} */
|
|
53
|
+
synapses: SynapsesType;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a copy-on-write mutation draft that tracks changed paths without
|
|
56
|
+
* cloning the whole store before every mutative update.
|
|
57
|
+
*/
|
|
58
|
+
_createMutationDraft(base: any, changedPaths: any): {
|
|
59
|
+
getNextState: () => any;
|
|
60
|
+
memory: any;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Only notify listeners that read properties which changed
|
|
64
|
+
*/
|
|
65
|
+
_notifyRelevantListeners(changedPaths: any): void;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a Proxy that tracks which properties are accessed during render
|
|
68
|
+
*
|
|
69
|
+
* WHY: This is the other half of the magic. By tracking what a component READS
|
|
70
|
+
* during its render, we build a precise dependency graph. If a component reads
|
|
71
|
+
* `state.user.name`, it will only re-render when `state.user.name` changes,
|
|
72
|
+
* not when `state.count` changes.
|
|
73
|
+
*/
|
|
74
|
+
_createAccessTrackingProxy(obj: any, accessedPaths: any, path?: string): any;
|
|
75
|
+
/**
|
|
76
|
+
* @returns {UnwrappedMemory<MemoryType>}
|
|
77
|
+
*/
|
|
78
|
+
get memory(): UnwrappedMemory<MemoryType>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Mapped type for the Memory configuration object.
|
|
82
|
+
* Allows each property to be the raw value OR a persisted wrapper.
|
|
83
|
+
*/
|
|
84
|
+
export type MemoryInput<T> = { [K in keyof T]: T[K] | import("./persist.js").Persisted<T[K]>; };
|
|
85
|
+
/**
|
|
86
|
+
* Deeply unwraps persisted values from the memory shape.
|
|
87
|
+
*/
|
|
88
|
+
export type UnwrappedMemory<T extends unknown> = { [K in keyof T]: T[K] extends import("./persist.js").Persisted<infer I> ? I : T[K]; };
|
|
89
|
+
export type Getter<T> = () => T;
|
|
90
|
+
export type Setter<T> = (updater: Partial<T> | ((state: T) => void | Partial<T> | unknown)) => void;
|
|
91
|
+
export type SynapsesBuilder<M, S> = (set: Setter<M>, get: Getter<M>) => S;
|
|
92
|
+
export type CortexConfig<M, S> = {
|
|
93
|
+
/**
|
|
94
|
+
* - The initial state configuration
|
|
95
|
+
*/
|
|
96
|
+
memory: MemoryInput<M>;
|
|
97
|
+
/**
|
|
98
|
+
* - The synapses builder function
|
|
99
|
+
*/
|
|
100
|
+
synapses: SynapsesBuilder<M, S>;
|
|
101
|
+
};
|
package/dist/css.d.ts
ADDED