@bromscandium/core 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.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/dep.d.ts +81 -0
- package/dist/dep.d.ts.map +1 -0
- package/dist/dep.js +119 -0
- package/dist/dep.js.map +1 -0
- package/dist/effect.d.ts +131 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +188 -0
- package/dist/effect.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/reactive.d.ts +72 -0
- package/dist/reactive.d.ts.map +1 -0
- package/dist/reactive.js +138 -0
- package/dist/reactive.js.map +1 -0
- package/dist/ref.d.ts +132 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +181 -0
- package/dist/ref.js.map +1 -0
- package/package.json +38 -0
- package/src/dep.d.ts +81 -0
- package/src/dep.d.ts.map +1 -0
- package/src/dep.js +119 -0
- package/src/dep.js.map +1 -0
- package/src/dep.ts +148 -0
- package/src/effect.d.ts +131 -0
- package/src/effect.d.ts.map +1 -0
- package/src/effect.js +188 -0
- package/src/effect.js.map +1 -0
- package/src/effect.ts +263 -0
- package/src/index.d.ts +5 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +6 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +38 -0
- package/src/reactive.d.ts +72 -0
- package/src/reactive.d.ts.map +1 -0
- package/src/reactive.js +138 -0
- package/src/reactive.js.map +1 -0
- package/src/reactive.ts +162 -0
- package/src/ref.d.ts +132 -0
- package/src/ref.d.ts.map +1 -0
- package/src/ref.js +181 -0
- package/src/ref.js.map +1 -0
- package/src/ref.ts +243 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy-based reactivity system for deep reactive state management.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Internal flags used to identify reactive objects.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ReactiveFlags: {
|
|
9
|
+
readonly IS_REACTIVE: "__b_isReactive";
|
|
10
|
+
readonly RAW: "__b_raw";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates a deeply reactive proxy of an object.
|
|
14
|
+
* Changes to the object or its nested properties will automatically trigger effects.
|
|
15
|
+
*
|
|
16
|
+
* @param target - The object to make reactive
|
|
17
|
+
* @returns A reactive proxy of the target object
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const state = reactive({ count: 0, nested: { value: 1 } });
|
|
22
|
+
* state.count++; // Triggers effects tracking 'count'
|
|
23
|
+
* state.nested.value++; // Triggers effects tracking nested 'value'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function reactive<T extends object>(target: T): T;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a value is a reactive proxy created by `reactive()`.
|
|
29
|
+
*
|
|
30
|
+
* @param value - The value to check
|
|
31
|
+
* @returns True if the value is a reactive proxy
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const state = reactive({ count: 0 });
|
|
36
|
+
* isReactive(state); // true
|
|
37
|
+
* isReactive({ count: 0 }); // false
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function isReactive(value: unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the raw, non-reactive version of a reactive object.
|
|
43
|
+
* Useful when you need to read values without triggering dependency tracking.
|
|
44
|
+
*
|
|
45
|
+
* @param observed - The reactive object to unwrap
|
|
46
|
+
* @returns The original non-reactive object
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const state = reactive({ count: 0 });
|
|
51
|
+
* const raw = toRaw(state);
|
|
52
|
+
* raw === state; // false
|
|
53
|
+
* isReactive(raw); // false
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function toRaw<T>(observed: T): T;
|
|
57
|
+
/**
|
|
58
|
+
* Marks an object so it will never be converted to a reactive proxy.
|
|
59
|
+
* Useful for values that should not be made reactive, like third-party class instances.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The object to mark as non-reactive
|
|
62
|
+
* @returns The same object, marked as raw
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const obj = markRaw({ count: 0 });
|
|
67
|
+
* const state = reactive({ data: obj });
|
|
68
|
+
* isReactive(state.data); // false - obj was marked raw
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function markRaw<T extends object>(value: T): T;
|
|
72
|
+
//# sourceMappingURL=reactive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../src/reactive.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;GAEG;AACH,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAqEvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAElD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAGvC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAOrD"}
|
package/dist/reactive.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy-based reactivity system for deep reactive state management.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import { track, trigger } from './dep.js';
|
|
6
|
+
const reactiveMap = new WeakMap();
|
|
7
|
+
const rawMap = new WeakMap();
|
|
8
|
+
/**
|
|
9
|
+
* Internal flags used to identify reactive objects.
|
|
10
|
+
*/
|
|
11
|
+
export const ReactiveFlags = {
|
|
12
|
+
IS_REACTIVE: '__b_isReactive',
|
|
13
|
+
RAW: '__b_raw',
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates a deeply reactive proxy of an object.
|
|
17
|
+
* Changes to the object or its nested properties will automatically trigger effects.
|
|
18
|
+
*
|
|
19
|
+
* @param target - The object to make reactive
|
|
20
|
+
* @returns A reactive proxy of the target object
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const state = reactive({ count: 0, nested: { value: 1 } });
|
|
25
|
+
* state.count++; // Triggers effects tracking 'count'
|
|
26
|
+
* state.nested.value++; // Triggers effects tracking nested 'value'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function reactive(target) {
|
|
30
|
+
if (reactiveMap.has(target)) {
|
|
31
|
+
return reactiveMap.get(target);
|
|
32
|
+
}
|
|
33
|
+
if (target[ReactiveFlags.IS_REACTIVE]) {
|
|
34
|
+
return target;
|
|
35
|
+
}
|
|
36
|
+
const proxy = new Proxy(target, {
|
|
37
|
+
get(target, key, receiver) {
|
|
38
|
+
if (key === ReactiveFlags.IS_REACTIVE) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (key === ReactiveFlags.RAW) {
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
const result = Reflect.get(target, key, receiver);
|
|
45
|
+
track(target, key);
|
|
46
|
+
if (typeof result === 'object' && result !== null) {
|
|
47
|
+
return reactive(result);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
},
|
|
51
|
+
set(target, key, value, receiver) {
|
|
52
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
53
|
+
const newValue = value?.[ReactiveFlags.RAW] || value;
|
|
54
|
+
const result = Reflect.set(target, key, newValue, receiver);
|
|
55
|
+
if (!Object.is(oldValue, newValue)) {
|
|
56
|
+
trigger(target, key);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
},
|
|
60
|
+
deleteProperty(target, key) {
|
|
61
|
+
const hadKey = Reflect.has(target, key);
|
|
62
|
+
const result = Reflect.deleteProperty(target, key);
|
|
63
|
+
if (hadKey && result) {
|
|
64
|
+
trigger(target, key);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
},
|
|
68
|
+
has(target, key) {
|
|
69
|
+
track(target, key);
|
|
70
|
+
return Reflect.has(target, key);
|
|
71
|
+
},
|
|
72
|
+
ownKeys(target) {
|
|
73
|
+
track(target, Symbol('iterate'));
|
|
74
|
+
return Reflect.ownKeys(target);
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
reactiveMap.set(target, proxy);
|
|
78
|
+
rawMap.set(proxy, target);
|
|
79
|
+
return proxy;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks if a value is a reactive proxy created by `reactive()`.
|
|
83
|
+
*
|
|
84
|
+
* @param value - The value to check
|
|
85
|
+
* @returns True if the value is a reactive proxy
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const state = reactive({ count: 0 });
|
|
90
|
+
* isReactive(state); // true
|
|
91
|
+
* isReactive({ count: 0 }); // false
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function isReactive(value) {
|
|
95
|
+
return !!(value && value[ReactiveFlags.IS_REACTIVE]);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the raw, non-reactive version of a reactive object.
|
|
99
|
+
* Useful when you need to read values without triggering dependency tracking.
|
|
100
|
+
*
|
|
101
|
+
* @param observed - The reactive object to unwrap
|
|
102
|
+
* @returns The original non-reactive object
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const state = reactive({ count: 0 });
|
|
107
|
+
* const raw = toRaw(state);
|
|
108
|
+
* raw === state; // false
|
|
109
|
+
* isReactive(raw); // false
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function toRaw(observed) {
|
|
113
|
+
const raw = observed?.[ReactiveFlags.RAW];
|
|
114
|
+
return raw ? toRaw(raw) : observed;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Marks an object so it will never be converted to a reactive proxy.
|
|
118
|
+
* Useful for values that should not be made reactive, like third-party class instances.
|
|
119
|
+
*
|
|
120
|
+
* @param value - The object to mark as non-reactive
|
|
121
|
+
* @returns The same object, marked as raw
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const obj = markRaw({ count: 0 });
|
|
126
|
+
* const state = reactive({ data: obj });
|
|
127
|
+
* isReactive(state.data); // false - obj was marked raw
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export function markRaw(value) {
|
|
131
|
+
Object.defineProperty(value, ReactiveFlags.IS_REACTIVE, {
|
|
132
|
+
configurable: true,
|
|
133
|
+
enumerable: false,
|
|
134
|
+
value: false,
|
|
135
|
+
});
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=reactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive.js","sourceRoot":"","sources":["../src/reactive.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,GAAG,IAAI,OAAO,EAAkB,CAAC;AAClD,MAAM,MAAM,GAAG,IAAI,OAAO,EAAkB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,WAAW,EAAE,gBAAgB;IAC7B,GAAG,EAAE,SAAS;C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AAM,GAAG,GAAI,QAAgB,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACnD,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CAAmB,KAAQ;IAChD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,WAAW,EAAE;QACtD,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/ref.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ref implementation for wrapping primitive and object values in reactive containers.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/** Internal flag used to identify ref objects */
|
|
6
|
+
export declare const RefFlag = "__b_isRef";
|
|
7
|
+
/**
|
|
8
|
+
* A reactive reference that wraps a value and tracks access to its `.value` property.
|
|
9
|
+
*/
|
|
10
|
+
export interface Ref<T = any> {
|
|
11
|
+
value: T;
|
|
12
|
+
readonly [RefFlag]: true;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A computed ref with a read-only value that is derived from other reactive state.
|
|
16
|
+
*/
|
|
17
|
+
export interface ComputedRef<T = any> extends Ref<T> {
|
|
18
|
+
readonly value: T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a reactive reference for a value.
|
|
22
|
+
* Object values are automatically made deeply reactive.
|
|
23
|
+
*
|
|
24
|
+
* @param value - The initial value for the ref
|
|
25
|
+
* @returns A reactive ref containing the value
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const count = ref(0);
|
|
30
|
+
* console.log(count.value); // 0
|
|
31
|
+
* count.value++; // Triggers effects
|
|
32
|
+
*
|
|
33
|
+
* const obj = ref({ nested: 1 });
|
|
34
|
+
* obj.value.nested++; // Also triggers effects (deep reactivity)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function ref<T>(value: T): Ref<T>;
|
|
38
|
+
export declare function ref<T = any>(): Ref<T | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a value is a ref created by `ref()` or `computed()`.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check
|
|
43
|
+
* @returns True if the value is a ref
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* isRef(ref(0)); // true
|
|
48
|
+
* isRef(0); // false
|
|
49
|
+
* isRef(computed(() => 1)); // true
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function isRef<T>(value: Ref<T> | unknown): value is Ref<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Unwraps a ref to get its inner value. Returns the value directly if not a ref.
|
|
55
|
+
*
|
|
56
|
+
* @param ref - A ref or plain value to unwrap
|
|
57
|
+
* @returns The unwrapped value
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* unref(ref(1)); // 1
|
|
62
|
+
* unref(1); // 1
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function unref<T>(ref: T | Ref<T>): T;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a ref that syncs with a property of a reactive object.
|
|
68
|
+
* The ref stays connected to the source object.
|
|
69
|
+
*
|
|
70
|
+
* @param object - The source reactive object
|
|
71
|
+
* @param key - The property key to create a ref for
|
|
72
|
+
* @returns A ref linked to the specified property
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const state = reactive({ count: 0 });
|
|
77
|
+
* const countRef = toRef(state, 'count');
|
|
78
|
+
* countRef.value++; // Also updates state.count
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function toRef<T extends object, K extends keyof T>(object: T, key: K): Ref<T[K]>;
|
|
82
|
+
/**
|
|
83
|
+
* Converts all properties of a reactive object into refs.
|
|
84
|
+
* Each ref is linked to the corresponding property on the source object.
|
|
85
|
+
*
|
|
86
|
+
* @param object - The source reactive object
|
|
87
|
+
* @returns An object with the same keys, where each value is a ref
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const state = reactive({ count: 0, name: 'test' });
|
|
92
|
+
* const { count, name } = toRefs(state);
|
|
93
|
+
* count.value++; // Updates state.count
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function toRefs<T extends object>(object: T): {
|
|
97
|
+
[K in keyof T]: Ref<T[K]>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* A shallow ref type (same interface as Ref but without deep reactivity).
|
|
101
|
+
*/
|
|
102
|
+
export type ShallowRef<T = any> = Ref<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a ref that does not make its value deeply reactive.
|
|
105
|
+
* Only reassigning `.value` will trigger effects, not mutations to nested properties.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The initial value for the shallow ref
|
|
108
|
+
* @returns A shallow ref containing the value
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const state = shallowRef({ nested: 0 });
|
|
113
|
+
* state.value.nested++; // Does NOT trigger effects
|
|
114
|
+
* state.value = { nested: 1 }; // Triggers effects
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function shallowRef<T>(value: T): ShallowRef<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Manually triggers effects that depend on a ref.
|
|
120
|
+
* Useful after mutating the inner value of a shallow ref.
|
|
121
|
+
*
|
|
122
|
+
* @param ref - The ref to trigger
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const state = shallowRef({ count: 0 });
|
|
127
|
+
* state.value.count++; // No automatic trigger
|
|
128
|
+
* triggerRef(state); // Manually trigger effects
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function triggerRef(ref: Ref): void;
|
|
132
|
+
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,iDAAiD;AACjD,eAAO,MAAM,OAAO,cAAc,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,GAAG;IAC1B,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,GAAG,CAAC,CAAC,CAAC;IAClD,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AA2CD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AACzC,wBAAgB,GAAG,CAAC,CAAC,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAQnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,CAEjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAE3C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EACvD,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,CAAC,GACL,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAeX;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAMjF;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;AAuBzC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAErD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAEzC"}
|
package/dist/ref.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ref implementation for wrapping primitive and object values in reactive containers.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
var _a, _b;
|
|
6
|
+
import { track, trigger, getActiveEffect } from './dep.js';
|
|
7
|
+
import { reactive, toRaw } from './reactive.js';
|
|
8
|
+
/** Internal flag used to identify ref objects */
|
|
9
|
+
export const RefFlag = '__b_isRef';
|
|
10
|
+
class RefImpl {
|
|
11
|
+
constructor(value) {
|
|
12
|
+
this[_a] = true;
|
|
13
|
+
this._rawValue = toRaw(value);
|
|
14
|
+
this._value = toReactive(value);
|
|
15
|
+
}
|
|
16
|
+
get value() {
|
|
17
|
+
trackRefValue(this);
|
|
18
|
+
return this._value;
|
|
19
|
+
}
|
|
20
|
+
set value(newValue) {
|
|
21
|
+
const rawNewValue = toRaw(newValue);
|
|
22
|
+
if (!Object.is(rawNewValue, this._rawValue)) {
|
|
23
|
+
this._rawValue = rawNewValue;
|
|
24
|
+
this._value = toReactive(newValue);
|
|
25
|
+
triggerRefValue(this);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
_a = RefFlag;
|
|
30
|
+
function toReactive(value) {
|
|
31
|
+
return typeof value === 'object' && value !== null
|
|
32
|
+
? reactive(value)
|
|
33
|
+
: value;
|
|
34
|
+
}
|
|
35
|
+
function trackRefValue(ref) {
|
|
36
|
+
if (getActiveEffect()) {
|
|
37
|
+
track(ref, 'value');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function triggerRefValue(ref) {
|
|
41
|
+
trigger(ref, 'value');
|
|
42
|
+
}
|
|
43
|
+
export function ref(value) {
|
|
44
|
+
if (isRef(value)) {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
return new RefImpl(value);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a value is a ref created by `ref()` or `computed()`.
|
|
51
|
+
*
|
|
52
|
+
* @param value - The value to check
|
|
53
|
+
* @returns True if the value is a ref
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* isRef(ref(0)); // true
|
|
58
|
+
* isRef(0); // false
|
|
59
|
+
* isRef(computed(() => 1)); // true
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function isRef(value) {
|
|
63
|
+
return !!(value && value[RefFlag] === true);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Unwraps a ref to get its inner value. Returns the value directly if not a ref.
|
|
67
|
+
*
|
|
68
|
+
* @param ref - A ref or plain value to unwrap
|
|
69
|
+
* @returns The unwrapped value
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* unref(ref(1)); // 1
|
|
74
|
+
* unref(1); // 1
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function unref(ref) {
|
|
78
|
+
return isRef(ref) ? ref.value : ref;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a ref that syncs with a property of a reactive object.
|
|
82
|
+
* The ref stays connected to the source object.
|
|
83
|
+
*
|
|
84
|
+
* @param object - The source reactive object
|
|
85
|
+
* @param key - The property key to create a ref for
|
|
86
|
+
* @returns A ref linked to the specified property
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const state = reactive({ count: 0 });
|
|
91
|
+
* const countRef = toRef(state, 'count');
|
|
92
|
+
* countRef.value++; // Also updates state.count
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export function toRef(object, key) {
|
|
96
|
+
const val = object[key];
|
|
97
|
+
if (isRef(val)) {
|
|
98
|
+
return val;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
get value() {
|
|
102
|
+
return object[key];
|
|
103
|
+
},
|
|
104
|
+
set value(newValue) {
|
|
105
|
+
object[key] = newValue;
|
|
106
|
+
},
|
|
107
|
+
[RefFlag]: true,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Converts all properties of a reactive object into refs.
|
|
112
|
+
* Each ref is linked to the corresponding property on the source object.
|
|
113
|
+
*
|
|
114
|
+
* @param object - The source reactive object
|
|
115
|
+
* @returns An object with the same keys, where each value is a ref
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const state = reactive({ count: 0, name: 'test' });
|
|
120
|
+
* const { count, name } = toRefs(state);
|
|
121
|
+
* count.value++; // Updates state.count
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export function toRefs(object) {
|
|
125
|
+
const result = {};
|
|
126
|
+
for (const key in object) {
|
|
127
|
+
result[key] = toRef(object, key);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
class ShallowRefImpl {
|
|
132
|
+
constructor(value) {
|
|
133
|
+
this[_b] = true;
|
|
134
|
+
this._value = value;
|
|
135
|
+
}
|
|
136
|
+
get value() {
|
|
137
|
+
trackRefValue(this);
|
|
138
|
+
return this._value;
|
|
139
|
+
}
|
|
140
|
+
set value(newValue) {
|
|
141
|
+
if (!Object.is(newValue, this._value)) {
|
|
142
|
+
this._value = newValue;
|
|
143
|
+
triggerRefValue(this);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_b = RefFlag;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a ref that does not make its value deeply reactive.
|
|
150
|
+
* Only reassigning `.value` will trigger effects, not mutations to nested properties.
|
|
151
|
+
*
|
|
152
|
+
* @param value - The initial value for the shallow ref
|
|
153
|
+
* @returns A shallow ref containing the value
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const state = shallowRef({ nested: 0 });
|
|
158
|
+
* state.value.nested++; // Does NOT trigger effects
|
|
159
|
+
* state.value = { nested: 1 }; // Triggers effects
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export function shallowRef(value) {
|
|
163
|
+
return new ShallowRefImpl(value);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Manually triggers effects that depend on a ref.
|
|
167
|
+
* Useful after mutating the inner value of a shallow ref.
|
|
168
|
+
*
|
|
169
|
+
* @param ref - The ref to trigger
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const state = shallowRef({ count: 0 });
|
|
174
|
+
* state.value.count++; // No automatic trigger
|
|
175
|
+
* triggerRef(state); // Manually trigger effects
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export function triggerRef(ref) {
|
|
179
|
+
triggerRefValue(ref);
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=ref.js.map
|
package/dist/ref.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":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AC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAOD,MAAM,cAAc;IAIlB,YAAY,KAAQ;QAFJ,QAAS,GAAG,IAAI,CAAC;QAG/B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,IAAI,KAAK;QACP,aAAa,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,KAAK,CAAC,QAAW;QACnB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;YACvB,eAAe,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;CACF;KAjBkB,OAAO;AAmB1B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAI,KAAQ;IACpC,OAAO,IAAI,cAAc,CAAC,KAAK,CAAkB,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,eAAe,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bromscandium/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "BromiumJS core reactivity system",
|
|
5
|
+
"author": "bromscandium",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/bromscandium/bromiumjs.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/bromscandium/bromiumjs#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/bromscandium/bromiumjs/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": ["bromium", "bromiumjs", "reactivity", "proxy", "signals"],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"dev": "tsc --watch"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/dep.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency tracking system for reactive state management.
|
|
3
|
+
* Uses WeakMap for automatic garbage collection of unused dependencies.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* An effect function that can be tracked and re-executed when dependencies change.
|
|
8
|
+
*/
|
|
9
|
+
export type EffectFn = (() => void) & {
|
|
10
|
+
deps: Set<Set<EffectFn>>;
|
|
11
|
+
options?: EffectOptions;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Configuration options for reactive effects.
|
|
15
|
+
*/
|
|
16
|
+
export interface EffectOptions {
|
|
17
|
+
/** If true, the effect will not run immediately upon creation */
|
|
18
|
+
lazy?: boolean;
|
|
19
|
+
/** Custom scheduler function to control when the effect runs */
|
|
20
|
+
scheduler?: (fn: EffectFn) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the currently executing effect, if any.
|
|
24
|
+
*
|
|
25
|
+
* @returns The active effect function or null if no effect is running
|
|
26
|
+
*/
|
|
27
|
+
export declare function getActiveEffect(): EffectFn | null;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the currently active effect.
|
|
30
|
+
*
|
|
31
|
+
* @param effect - The effect to set as active, or null to clear
|
|
32
|
+
*/
|
|
33
|
+
export declare function setActiveEffect(effect: EffectFn | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* Pushes an effect onto the effect stack and sets it as active.
|
|
36
|
+
* Used internally when running nested effects.
|
|
37
|
+
*
|
|
38
|
+
* @param effect - The effect to push onto the stack
|
|
39
|
+
*/
|
|
40
|
+
export declare function pushEffect(effect: EffectFn): void;
|
|
41
|
+
/**
|
|
42
|
+
* Pops the current effect from the stack and restores the previous active effect.
|
|
43
|
+
* Used internally when a nested effect completes.
|
|
44
|
+
*/
|
|
45
|
+
export declare function popEffect(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Tracks a dependency between the currently active effect and a reactive property.
|
|
48
|
+
* Called automatically when a reactive property is accessed during effect execution.
|
|
49
|
+
*
|
|
50
|
+
* @param target - The reactive object being accessed
|
|
51
|
+
* @param key - The property key being accessed
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // Typically called internally by reactive proxies
|
|
56
|
+
* track(state, 'count');
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function track(target: object, key: string | symbol): void;
|
|
60
|
+
/**
|
|
61
|
+
* Triggers all effects that depend on a reactive property.
|
|
62
|
+
* Called automatically when a reactive property is modified.
|
|
63
|
+
*
|
|
64
|
+
* @param target - The reactive object being modified
|
|
65
|
+
* @param key - The property key being modified
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* // Typically called internally by reactive proxies
|
|
70
|
+
* trigger(state, 'count');
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function trigger(target: object, key: string | symbol): void;
|
|
74
|
+
/**
|
|
75
|
+
* Removes an effect from all its dependency sets.
|
|
76
|
+
* Called before re-running an effect to ensure fresh dependency tracking.
|
|
77
|
+
*
|
|
78
|
+
* @param effect - The effect to clean up
|
|
79
|
+
*/
|
|
80
|
+
export declare function cleanup(effect: EffectFn): void;
|
|
81
|
+
//# sourceMappingURL=dep.d.ts.map
|
package/src/dep.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dep.d.ts","sourceRoot":"","sources":["dep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG;IACpC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;CACpC;AAOD;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,QAAQ,GAAG,IAAI,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAE7D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAGjD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAGhC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBhE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsBlE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAK9C"}
|