@madronejs/core 1.0.18 → 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/dist/MadroneVue3-2XGQsm-S.cjs +1 -0
- package/dist/MadroneVue3-C5d5X6U2.js +557 -0
- package/dist/core.cjs +1 -0
- package/dist/core.js +75 -445
- package/dist/vue.cjs +1 -0
- package/dist/vue.js +6 -0
- package/package.json +27 -15
- package/types/auto.d.ts +93 -1
- package/types/decorate.d.ts +128 -15
- package/types/global.d.ts +141 -7
- package/types/integrations/MadroneState.d.ts +97 -16
- package/types/integrations/MadroneVue3.d.ts +64 -1
- package/types/integrations/vue.d.ts +42 -0
- package/types/interfaces.d.ts +175 -8
- package/types/reactivity/Computed.d.ts +46 -3
- package/types/reactivity/Observer.d.ts +92 -2
- package/types/reactivity/Reactive.d.ts +47 -7
- package/types/reactivity/Watcher.d.ts +55 -6
- package/types/reactivity/global.d.ts +68 -28
- package/types/reactivity/interfaces.d.ts +53 -11
- package/types/reactivity/typeHandlers.d.ts +9 -2
- package/types/util.d.ts +109 -15
- package/types/__spec__/decorateComputed.spec.d.ts +0 -2
- package/types/__spec__/decorateReactive.spec.d.ts +0 -2
- package/types/__spec__/examples.spec.d.ts +0 -2
- package/types/__spec__/merge.spec.d.ts +0 -2
- package/types/integrations/__spec__/madroneState.spec.d.ts +0 -2
- package/types/integrations/__spec__/testAccess.d.ts +0 -2
- package/types/integrations/__spec__/testAll.d.ts +0 -4
- package/types/integrations/__spec__/testAuto.d.ts +0 -2
- package/types/integrations/__spec__/testClass.d.ts +0 -2
- package/types/integrations/__spec__/testVue.d.ts +0 -2
- package/types/integrations/__spec__/vue3.spec.d.ts +0 -2
- package/types/reactivity/__spec__/observer.spec.d.ts +0 -2
- package/types/reactivity/__spec__/observer_array.spec.d.ts +0 -2
- package/types/reactivity/__spec__/observer_object.spec.d.ts +0 -2
- package/types/reactivity/__spec__/observer_set.xspec.d.ts +0 -2
- package/types/reactivity/__spec__/reactive.spec.d.ts +0 -2
- package/types/reactivity/__spec__/reactive_array.spec.d.ts +0 -2
- package/types/reactivity/__spec__/reactive_object.spec.d.ts +0 -2
- package/types/reactivity/__spec__/reactive_set.xspec.d.ts +0 -2
- package/types/reactivity/__spec__/watcher.spec.d.ts +0 -2
package/types/auto.d.ts
CHANGED
|
@@ -1,7 +1,99 @@
|
|
|
1
1
|
import { MadroneDescriptor, WatcherOptions } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a single reactive or computed property on an object.
|
|
4
|
+
*
|
|
5
|
+
* If the descriptor has a `get` function, it creates a computed property that
|
|
6
|
+
* automatically tracks dependencies and caches its result. Otherwise, it creates
|
|
7
|
+
* a reactive property that triggers updates when changed.
|
|
8
|
+
*
|
|
9
|
+
* @param obj - The target object to define the property on
|
|
10
|
+
* @param key - The property name to define
|
|
11
|
+
* @param descriptor - Configuration for the property including getter/setter or value
|
|
12
|
+
* @throws Error if no integration is configured (call `Madrone.use()` first)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const state = { count: 0 };
|
|
17
|
+
* define(state, 'doubled', {
|
|
18
|
+
* get() { return this.count * 2; },
|
|
19
|
+
* cache: true
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
2
23
|
export declare function define<T extends object>(obj: T, key: string, descriptor: MadroneDescriptor): void;
|
|
24
|
+
/**
|
|
25
|
+
* Automatically makes all properties on an object reactive.
|
|
26
|
+
*
|
|
27
|
+
* Iterates through all own properties of the object and converts them:
|
|
28
|
+
* - Properties with getters become cached computed properties
|
|
29
|
+
* - Regular properties become deeply reactive by default
|
|
30
|
+
*
|
|
31
|
+
* This is the primary way to create reactive state in Madrone.
|
|
32
|
+
*
|
|
33
|
+
* @param obj - The object to make reactive
|
|
34
|
+
* @param objDescriptors - Optional per-property configuration overrides
|
|
35
|
+
* @returns The same object, now with reactive properties
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const state = auto({
|
|
40
|
+
* count: 0,
|
|
41
|
+
* get doubled() { return this.count * 2; }
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* state.count = 5;
|
|
45
|
+
* console.log(state.doubled); // 10
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // With descriptor overrides
|
|
51
|
+
* const state = auto(
|
|
52
|
+
* { items: [] },
|
|
53
|
+
* { items: { deep: false } } // Shallow reactivity for items
|
|
54
|
+
* );
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
3
57
|
export declare function auto<T extends object>(obj: T, objDescriptors?: {
|
|
4
58
|
[K in keyof T]?: MadroneDescriptor;
|
|
5
59
|
}): T;
|
|
6
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Watches a reactive expression and calls a handler when its value changes.
|
|
62
|
+
*
|
|
63
|
+
* The `scope` function is called immediately to establish dependencies.
|
|
64
|
+
* Whenever any reactive property accessed within `scope` changes, the
|
|
65
|
+
* function re-runs and `handler` is called with the new and old values.
|
|
66
|
+
*
|
|
67
|
+
* @param scope - A function that returns the value to watch. All reactive
|
|
68
|
+
* properties accessed within this function become dependencies.
|
|
69
|
+
* @param handler - Callback invoked when the watched value changes
|
|
70
|
+
* @param options - Optional configuration
|
|
71
|
+
* @param options.immediate - If true, calls handler immediately with current value
|
|
72
|
+
* @returns A disposer function that stops watching when called
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const state = auto({ count: 0 });
|
|
77
|
+
*
|
|
78
|
+
* const stop = watch(
|
|
79
|
+
* () => state.count,
|
|
80
|
+
* (newVal, oldVal) => console.log(`Changed from ${oldVal} to ${newVal}`)
|
|
81
|
+
* );
|
|
82
|
+
*
|
|
83
|
+
* state.count = 5; // logs: "Changed from 0 to 5"
|
|
84
|
+
* stop(); // Stop watching
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* // Watch with immediate execution
|
|
90
|
+
* watch(
|
|
91
|
+
* () => state.count,
|
|
92
|
+
* (val) => console.log(`Count is ${val}`),
|
|
93
|
+
* { immediate: true }
|
|
94
|
+
* );
|
|
95
|
+
* // Immediately logs: "Count is 0"
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function watch<T>(scope: () => T, handler: (val: T, old: T) => void, options?: WatcherOptions): (() => void) | undefined;
|
|
7
99
|
//# sourceMappingURL=auto.d.ts.map
|
package/types/decorate.d.ts
CHANGED
|
@@ -1,24 +1,137 @@
|
|
|
1
|
-
import { DecoratorDescriptorType } from './interfaces';
|
|
2
|
-
export declare function classMixin(...mixins: Array<() => any>): (target: () => any) => void;
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* @module decorate
|
|
3
|
+
*
|
|
4
|
+
* TypeScript decorators for class-based reactive state management.
|
|
5
|
+
*
|
|
6
|
+
* Provides `@reactive` and `@computed` decorators that enable automatic
|
|
7
|
+
* reactivity on class properties and getters. These decorators lazily
|
|
8
|
+
* initialize reactive properties on first access, making them efficient
|
|
9
|
+
* for large class hierarchies.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { reactive, computed } from '@madronejs/core';
|
|
14
|
+
*
|
|
15
|
+
* class Counter {
|
|
16
|
+
* @reactive count = 0;
|
|
17
|
+
*
|
|
18
|
+
* @computed get doubled() {
|
|
19
|
+
* return this.count * 2;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
9
23
|
*/
|
|
10
|
-
|
|
24
|
+
import { DecoratorDescriptorType, Constructor } from './interfaces';
|
|
25
|
+
/**
|
|
26
|
+
* Class decorator that mixes in methods from other classes.
|
|
27
|
+
*
|
|
28
|
+
* Copies all prototype properties from the mixin classes onto the
|
|
29
|
+
* decorated class. Useful for composing behavior from multiple sources.
|
|
30
|
+
*
|
|
31
|
+
* @param mixins - Classes whose prototypes will be mixed in
|
|
32
|
+
* @returns A class decorator function
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* class Timestamped {
|
|
37
|
+
* createdAt = Date.now();
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* class Serializable {
|
|
41
|
+
* toJSON() { return JSON.stringify(this); }
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* @classMixin(Timestamped, Serializable)
|
|
45
|
+
* class Model {
|
|
46
|
+
* name: string;
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* const model = new Model();
|
|
50
|
+
* model.toJSON(); // Works - mixed in from Serializable
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function classMixin(...mixins: Constructor[]): (target: Constructor) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Decorator that creates a cached computed property from a getter.
|
|
56
|
+
*
|
|
57
|
+
* When applied to a getter, the computed value is cached and only recalculated
|
|
58
|
+
* when its reactive dependencies change. This provides efficient derived state
|
|
59
|
+
* that automatically stays in sync with source data.
|
|
60
|
+
*
|
|
61
|
+
* The decorator lazily initializes the computed property on first access,
|
|
62
|
+
* so it works correctly with class inheritance and instance creation.
|
|
63
|
+
*
|
|
64
|
+
* @param target - The class prototype
|
|
65
|
+
* @param key - The property name
|
|
66
|
+
* @param descriptor - The property descriptor containing the getter
|
|
67
|
+
* @returns Modified property descriptor with caching behavior
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { reactive, computed } from '@madronejs/core';
|
|
72
|
+
*
|
|
73
|
+
* class ShoppingCart {
|
|
74
|
+
* @reactive items: Array<{ price: number }> = [];
|
|
75
|
+
*
|
|
76
|
+
* @computed get total() {
|
|
77
|
+
* return this.items.reduce((sum, item) => sum + item.price, 0);
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* @computed get isEmpty() {
|
|
81
|
+
* return this.items.length === 0;
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* const cart = new ShoppingCart();
|
|
86
|
+
* cart.items.push({ price: 10 });
|
|
87
|
+
* console.log(cart.total); // 10 (computed once)
|
|
88
|
+
* console.log(cart.total); // 10 (cached, no recalculation)
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function computed(target: object, key: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
11
92
|
export declare namespace computed {
|
|
12
|
-
var configure: (descriptorOverrides: DecoratorDescriptorType) => (target:
|
|
93
|
+
var configure: (descriptorOverrides: DecoratorDescriptorType) => (target: object, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
13
94
|
}
|
|
14
95
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
96
|
+
* Decorator that makes a class property reactive.
|
|
97
|
+
*
|
|
98
|
+
* When the property value changes, any computed properties or watchers
|
|
99
|
+
* that depend on it will automatically update. By default, reactivity
|
|
100
|
+
* is deep - nested objects and arrays will also be reactive.
|
|
101
|
+
*
|
|
102
|
+
* The decorator lazily initializes reactivity on first access, making
|
|
103
|
+
* it efficient for classes with many properties that may not all be used.
|
|
104
|
+
*
|
|
105
|
+
* @param target - The class prototype (or constructor for static properties)
|
|
106
|
+
* @param key - The property name
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { reactive, computed, watch } from '@madronejs/core';
|
|
111
|
+
*
|
|
112
|
+
* class User {
|
|
113
|
+
* @reactive name = 'Anonymous';
|
|
114
|
+
* @reactive preferences = { theme: 'dark' };
|
|
115
|
+
*
|
|
116
|
+
* @computed get greeting() {
|
|
117
|
+
* return `Hello, ${this.name}!`;
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
*
|
|
121
|
+
* const user = new User();
|
|
122
|
+
*
|
|
123
|
+
* watch(
|
|
124
|
+
* () => user.name,
|
|
125
|
+
* (name) => console.log(`Name changed to ${name}`)
|
|
126
|
+
* );
|
|
127
|
+
*
|
|
128
|
+
* user.name = 'Alice'; // Triggers watcher, updates greeting
|
|
129
|
+
* user.preferences.theme = 'light'; // Deep reactivity works
|
|
130
|
+
* ```
|
|
18
131
|
*/
|
|
19
|
-
export declare function reactive(target:
|
|
132
|
+
export declare function reactive(target: object, key: string): void;
|
|
20
133
|
export declare namespace reactive {
|
|
21
|
-
var shallow: (target:
|
|
22
|
-
var configure: (descriptorOverrides: DecoratorDescriptorType) => (target:
|
|
134
|
+
var shallow: (target: object, key: string) => void;
|
|
135
|
+
var configure: (descriptorOverrides: DecoratorDescriptorType) => (target: object, key: string) => void;
|
|
23
136
|
}
|
|
24
137
|
//# sourceMappingURL=decorate.d.ts.map
|
package/types/global.d.ts
CHANGED
|
@@ -1,12 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module global
|
|
3
|
+
*
|
|
4
|
+
* Global state management for Madrone integrations and reactive object tracking.
|
|
5
|
+
*
|
|
6
|
+
* Madrone uses a plugin architecture where "integrations" provide the actual
|
|
7
|
+
* reactivity implementation. This module manages the global integration registry
|
|
8
|
+
* and provides utilities for tracking object access patterns.
|
|
9
|
+
*/
|
|
1
10
|
import { Integration } from './interfaces';
|
|
11
|
+
/**
|
|
12
|
+
* Returns all currently registered integrations.
|
|
13
|
+
*
|
|
14
|
+
* Integrations are the pluggable backends that provide reactivity.
|
|
15
|
+
* Multiple integrations can be registered, though typically only one is used.
|
|
16
|
+
*
|
|
17
|
+
* @returns An array of all registered Integration instances
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { getIntegrations } from '@madronejs/core';
|
|
22
|
+
*
|
|
23
|
+
* const integrations = getIntegrations();
|
|
24
|
+
* console.log(`${integrations.length} integrations registered`);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
2
27
|
export declare function getIntegrations(): Array<Integration>;
|
|
28
|
+
/**
|
|
29
|
+
* Registers a new integration with Madrone.
|
|
30
|
+
*
|
|
31
|
+
* The most recently added integration becomes the active one used by
|
|
32
|
+
* `auto()`, `define()`, and other reactive primitives. Integrations
|
|
33
|
+
* provide methods for creating reactive properties, computed values,
|
|
34
|
+
* and watchers.
|
|
35
|
+
*
|
|
36
|
+
* @param integration - The integration to register
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import Madrone, { MadroneState } from '@madronejs/core';
|
|
41
|
+
*
|
|
42
|
+
* // Register the built-in state integration
|
|
43
|
+
* Madrone.use(MadroneState);
|
|
44
|
+
*
|
|
45
|
+
* // Or register directly
|
|
46
|
+
* addIntegration(MadroneState);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
3
49
|
export declare function addIntegration(integration: Integration): void;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Removes a previously registered integration.
|
|
52
|
+
*
|
|
53
|
+
* After removal, the most recently added remaining integration becomes active.
|
|
54
|
+
* If no integrations remain, reactive operations will throw errors.
|
|
55
|
+
*
|
|
56
|
+
* @param integration - The integration to remove
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { removeIntegration, MadroneState } from '@madronejs/core';
|
|
61
|
+
*
|
|
62
|
+
* // Remove when switching integrations or cleaning up
|
|
63
|
+
* removeIntegration(MadroneState);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function removeIntegration(integration: Integration): void;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the currently active integration.
|
|
69
|
+
*
|
|
70
|
+
* This is the integration that will be used by `auto()`, `define()`,
|
|
71
|
+
* `watch()`, and other reactive primitives. Returns undefined if no
|
|
72
|
+
* integration has been registered.
|
|
73
|
+
*
|
|
74
|
+
* @returns The current active Integration, or undefined if none registered
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { getIntegration } from '@madronejs/core';
|
|
79
|
+
*
|
|
80
|
+
* const integration = getIntegration();
|
|
81
|
+
* if (!integration) {
|
|
82
|
+
* console.warn('No integration configured - call Madrone.use() first');
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function getIntegration(): Integration | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Unwraps a reactive proxy to get the underlying raw object.
|
|
89
|
+
*
|
|
90
|
+
* When you create reactive state with `auto()` or `Reactive()`, the returned
|
|
91
|
+
* object is actually a Proxy. This function returns the original object
|
|
92
|
+
* without the reactive wrapper, which is useful for:
|
|
93
|
+
* - Comparing object identity
|
|
94
|
+
* - Passing to external libraries that don't work with Proxies
|
|
95
|
+
* - Debugging reactive behavior
|
|
96
|
+
*
|
|
97
|
+
* @typeParam T - The type of the object
|
|
98
|
+
* @param obj - The potentially reactive object to unwrap
|
|
99
|
+
* @returns The raw underlying object without reactive proxy
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { auto, toRaw } from '@madronejs/core';
|
|
104
|
+
*
|
|
105
|
+
* const original = { count: 0 };
|
|
106
|
+
* const reactive = auto(original);
|
|
107
|
+
*
|
|
108
|
+
* console.log(reactive === original); // false (reactive is a Proxy)
|
|
109
|
+
* console.log(toRaw(reactive) === original); // true
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function toRaw<T extends object>(obj: T): T;
|
|
113
|
+
/**
|
|
114
|
+
* Records that a reactive object was accessed at the current time.
|
|
115
|
+
*
|
|
116
|
+
* This is called internally by reactive getters to track when objects
|
|
117
|
+
* are read. Used for debugging and performance analysis.
|
|
118
|
+
*
|
|
119
|
+
* @param obj - The object that was accessed
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
9
122
|
export declare function objectAccessed(obj: object): void;
|
|
10
|
-
/**
|
|
11
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Returns the timestamp of when a reactive object was last accessed.
|
|
125
|
+
*
|
|
126
|
+
* Useful for debugging reactive behavior or implementing features like
|
|
127
|
+
* "last viewed" timestamps without additional tracking code.
|
|
128
|
+
*
|
|
129
|
+
* @param obj - The reactive object to check
|
|
130
|
+
* @returns Unix timestamp (milliseconds) of last access, or undefined if never accessed
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { auto, lastAccessed } from '@madronejs/core';
|
|
135
|
+
*
|
|
136
|
+
* const state = auto({ count: 0 });
|
|
137
|
+
*
|
|
138
|
+
* console.log(lastAccessed(state)); // undefined (not accessed yet)
|
|
139
|
+
*
|
|
140
|
+
* const value = state.count; // access the property
|
|
141
|
+
*
|
|
142
|
+
* console.log(lastAccessed(state)); // 1702345678901 (timestamp)
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function lastAccessed(obj: object): number | undefined;
|
|
12
146
|
//# sourceMappingURL=global.d.ts.map
|
|
@@ -1,25 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module MadroneState
|
|
3
|
+
*
|
|
4
|
+
* Standalone reactivity integration using Madrone's built-in reactive system.
|
|
5
|
+
*
|
|
6
|
+
* This is the default integration for Madrone, providing a complete reactivity
|
|
7
|
+
* implementation based on JavaScript Proxies. It's the recommended integration
|
|
8
|
+
* for non-Vue applications.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import Madrone, { MadroneState, auto } from '@madronejs/core';
|
|
13
|
+
*
|
|
14
|
+
* // Initialize with the integration
|
|
15
|
+
* Madrone.use(MadroneState);
|
|
16
|
+
*
|
|
17
|
+
* // Now use reactive features
|
|
18
|
+
* const state = auto({ count: 0 });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import { Integration, IntegrationOptions, MadroneComputedDescriptor, MadronePropertyDescriptor } from '../interfaces';
|
|
2
22
|
import { ReactiveOptions } from '../reactivity/interfaces';
|
|
3
23
|
import { ObservableHooksType } from '../reactivity/Observer';
|
|
4
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Configuration options for MadroneState integration.
|
|
26
|
+
*
|
|
27
|
+
* Allows customizing the behavior of reactive properties and computed values.
|
|
28
|
+
*
|
|
29
|
+
* @typeParam T - The type of computed values (for typing onChange callbacks)
|
|
30
|
+
*/
|
|
31
|
+
export type MadroneStateOptions<T = unknown> = {
|
|
32
|
+
/** Options passed to Reactive() for property creation */
|
|
5
33
|
reactive?: ReactiveOptions;
|
|
34
|
+
/** Hooks for computed property lifecycle events */
|
|
6
35
|
computed?: ObservableHooksType<T>;
|
|
7
36
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export declare function
|
|
37
|
+
/**
|
|
38
|
+
* Creates a property descriptor for a computed property.
|
|
39
|
+
*
|
|
40
|
+
* The descriptor can be used with Object.defineProperty or stored
|
|
41
|
+
* for later use. If caching is enabled, creates a Computed observable
|
|
42
|
+
* that tracks dependencies automatically.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam T - The computed value type
|
|
45
|
+
* @param name - Property name (used for debugging)
|
|
46
|
+
* @param config - Computed property configuration
|
|
47
|
+
* @param options - Optional hooks for lifecycle events
|
|
48
|
+
* @returns A PropertyDescriptor with reactive getter/setter
|
|
49
|
+
*/
|
|
50
|
+
export declare function describeComputed<T = unknown>(name: string, config: MadroneComputedDescriptor, options?: MadroneStateOptions<T>): PropertyDescriptor;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a property descriptor for a reactive property.
|
|
53
|
+
*
|
|
54
|
+
* The descriptor can be used with Object.defineProperty or stored
|
|
55
|
+
* for later use. Creates a Reactive proxy internally to track changes.
|
|
56
|
+
*
|
|
57
|
+
* @param name - Property name (used for debugging)
|
|
58
|
+
* @param config - Reactive property configuration
|
|
59
|
+
* @param options - Optional hooks for lifecycle events
|
|
60
|
+
* @returns A PropertyDescriptor with reactive getter/setter
|
|
61
|
+
*/
|
|
62
|
+
export declare function describeProperty(name: string, config: MadronePropertyDescriptor, options?: MadroneStateOptions): PropertyDescriptor;
|
|
63
|
+
/**
|
|
64
|
+
* Defines a computed property directly on an object.
|
|
65
|
+
*
|
|
66
|
+
* Shorthand for calling describeComputed and Object.defineProperty.
|
|
67
|
+
*
|
|
68
|
+
* @param target - The object to define the property on
|
|
69
|
+
* @param name - The property name
|
|
70
|
+
* @param config - Computed configuration
|
|
71
|
+
* @param options - Integration-specific options
|
|
72
|
+
*/
|
|
73
|
+
export declare function defineComputed(target: object, name: string, config: MadroneComputedDescriptor, options?: IntegrationOptions): void;
|
|
74
|
+
/**
|
|
75
|
+
* Defines a reactive property directly on an object.
|
|
76
|
+
*
|
|
77
|
+
* Shorthand for calling describeProperty and Object.defineProperty.
|
|
78
|
+
*
|
|
79
|
+
* @param target - The object to define the property on
|
|
80
|
+
* @param name - The property name
|
|
81
|
+
* @param config - Reactive property configuration
|
|
82
|
+
* @param options - Integration-specific options
|
|
83
|
+
*/
|
|
84
|
+
export declare function defineProperty(target: object, name: string, config: MadronePropertyDescriptor, options?: IntegrationOptions): void;
|
|
85
|
+
/**
|
|
86
|
+
* The standalone MadroneState integration.
|
|
87
|
+
*
|
|
88
|
+
* Provides a complete reactivity system using JavaScript Proxies.
|
|
89
|
+
* This is the recommended integration for non-Vue applications.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import Madrone, { MadroneState } from '@madronejs/core';
|
|
94
|
+
*
|
|
95
|
+
* Madrone.use(MadroneState);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
22
98
|
declare const MadroneState: Integration;
|
|
23
99
|
export default MadroneState;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a watcher that reacts to changes in reactive expressions.
|
|
102
|
+
*
|
|
103
|
+
* Re-exported from the reactivity module for convenience.
|
|
104
|
+
*/
|
|
24
105
|
export { Watcher as watch } from '../reactivity';
|
|
25
106
|
//# sourceMappingURL=MadroneState.d.ts.map
|
|
@@ -1,3 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module MadroneVue3
|
|
3
|
+
*
|
|
4
|
+
* Vue 3 integration for Madrone, bridging Madrone's reactivity with Vue's system.
|
|
5
|
+
*
|
|
6
|
+
* This integration allows you to use Madrone's composition patterns and decorators
|
|
7
|
+
* while having reactivity work seamlessly with Vue 3's rendering system. Vue
|
|
8
|
+
* components will automatically re-render when Madrone state changes.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import Madrone from '@madronejs/core';
|
|
13
|
+
* import { MadroneVue3 } from '@madronejs/core';
|
|
14
|
+
* import { reactive, toRaw } from '../../node_modules/vue3';
|
|
15
|
+
*
|
|
16
|
+
* // Initialize with Vue 3's reactive system
|
|
17
|
+
* Madrone.use(MadroneVue3({ reactive, toRaw }));
|
|
18
|
+
*
|
|
19
|
+
* // Now Madrone state works with Vue components
|
|
20
|
+
* const store = auto({
|
|
21
|
+
* count: 0,
|
|
22
|
+
* get doubled() { return this.count * 2; }
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
1
26
|
import type { Integration } from '../interfaces';
|
|
2
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Options for creating a Vue 3 integration.
|
|
29
|
+
*/
|
|
30
|
+
export interface MadroneVue3Options {
|
|
31
|
+
/** Vue's `reactive()` function from '../../node_modules/vue3' */
|
|
32
|
+
reactive: <T extends object>(target: T) => unknown;
|
|
33
|
+
/** Vue's `toRaw()` function from '../../node_modules/vue3' */
|
|
34
|
+
toRaw: <T>(proxy: T) => T;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a Vue 3-compatible integration for Madrone.
|
|
38
|
+
*
|
|
39
|
+
* This factory function creates an integration that bridges Madrone's
|
|
40
|
+
* reactivity with Vue 3's reactive system. Changes to Madrone state
|
|
41
|
+
* will trigger Vue component re-renders.
|
|
42
|
+
*
|
|
43
|
+
* For simpler setup, use the pre-configured `madrone/integrations/vue` module instead.
|
|
44
|
+
*
|
|
45
|
+
* @param options - Vue 3 reactivity functions
|
|
46
|
+
* @param options.reactive - Vue's `reactive()` function from '../../node_modules/vue3'
|
|
47
|
+
* @param options.toRaw - Vue's `toRaw()` function from '../../node_modules/vue3'
|
|
48
|
+
* @returns An Integration compatible with Madrone.use()
|
|
49
|
+
* @throws Error if reactive function is not provided
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Option 1: Use the pre-configured module (recommended)
|
|
54
|
+
* import Madrone from '@madronejs/core';
|
|
55
|
+
* import { MadroneVue } from '@madronejs/core';
|
|
56
|
+
* Madrone.use(MadroneVue);
|
|
57
|
+
*
|
|
58
|
+
* // Option 2: Manual configuration
|
|
59
|
+
* import Madrone from '@madronejs/core';
|
|
60
|
+
* import { MadroneVue3 as createMadroneVue3 } from '@madronejs/core';
|
|
61
|
+
* import { reactive, toRaw } from '../../node_modules/vue3';
|
|
62
|
+
* Madrone.use(createMadroneVue3({ reactive, toRaw }));
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export default function MadroneVue3(options: MadroneVue3Options): Integration;
|
|
3
66
|
//# sourceMappingURL=MadroneVue3.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vue
|
|
3
|
+
*
|
|
4
|
+
* Pre-configured Vue 3 integration for Madrone.
|
|
5
|
+
*
|
|
6
|
+
* This module automatically imports Vue's reactivity functions, so you don't
|
|
7
|
+
* need to pass them manually. Just import and use directly.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import Madrone from '@madronejs/core';
|
|
12
|
+
* import { MadroneVue } from '@madronejs/core';
|
|
13
|
+
*
|
|
14
|
+
* Madrone.use(MadroneVue);
|
|
15
|
+
*
|
|
16
|
+
* // That's it! Madrone now works with Vue's reactivity
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Pre-configured Vue 3 integration.
|
|
21
|
+
*
|
|
22
|
+
* Uses Vue's `reactive` and `toRaw` functions automatically.
|
|
23
|
+
* This is the recommended way to use Madrone with Vue 3.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import Madrone from '@madronejs/core';
|
|
28
|
+
* import { MadroneVue } from '@madronejs/core';
|
|
29
|
+
*
|
|
30
|
+
* // Simple one-liner setup
|
|
31
|
+
* Madrone.use(MadroneVue);
|
|
32
|
+
*
|
|
33
|
+
* // Create reactive state that works with Vue components
|
|
34
|
+
* const store = auto({
|
|
35
|
+
* count: 0,
|
|
36
|
+
* get doubled() { return this.count * 2; }
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const MadroneVue: import("..").Integration;
|
|
41
|
+
export default MadroneVue;
|
|
42
|
+
//# sourceMappingURL=vue.d.ts.map
|