rumious 2.1.2 → 2.1.3
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/context/context.d.ts +6 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
@@ -1,9 +1,15 @@
|
|
1
|
+
import { RumiousState } from '../state/index.js';
|
2
|
+
export type RumiousContextReactive<T extends {}> = {
|
3
|
+
[K in keyof T]: RumiousState<T[K]>;
|
4
|
+
};
|
1
5
|
export declare class RumiousContext<T extends {}> {
|
2
6
|
values: T;
|
3
7
|
events: Record<string, Set<(...args: any[]) => void>>;
|
8
|
+
private states;
|
4
9
|
constructor(values: T);
|
5
10
|
set<K extends keyof T>(key: K, value: T[K]): void;
|
6
11
|
get<K extends keyof T>(key: K): T[K];
|
12
|
+
reactive<K extends keyof T>(key: K): RumiousState<T[K]>;
|
7
13
|
emit(event: string, ...args: any[]): void;
|
8
14
|
on(event: string, fn: (...args: any[]) => void): void;
|
9
15
|
off(event: string, fn?: (...args: any[]) => void): void;
|
package/dist/index.js
CHANGED
@@ -1100,15 +1100,23 @@ class RumiousModule {
|
|
1100
1100
|
class RumiousContext {
|
1101
1101
|
values;
|
1102
1102
|
events = {};
|
1103
|
+
states = {};
|
1103
1104
|
constructor(values) {
|
1104
1105
|
this.values = values;
|
1105
1106
|
}
|
1106
1107
|
set(key, value) {
|
1107
1108
|
this.values[key] = value;
|
1109
|
+
if (this.states[key])
|
1110
|
+
this.states[key].set(value);
|
1108
1111
|
}
|
1109
1112
|
get(key) {
|
1110
1113
|
return this.values[key];
|
1111
1114
|
}
|
1115
|
+
reactive(key) {
|
1116
|
+
if (!this.states[key])
|
1117
|
+
this.states[key] = createState(this.values[key]);
|
1118
|
+
return this.states[key];
|
1119
|
+
}
|
1112
1120
|
emit(event, ...args) {
|
1113
1121
|
const listeners = this.events[event];
|
1114
1122
|
if (listeners) {
|