rumious 2.1.1 → 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 +20 -1
- package/dist/state/store.d.ts +2 -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
@@ -410,10 +410,21 @@ class RumiousStore {
|
|
410
410
|
states = {};
|
411
411
|
constructor(value) {
|
412
412
|
this.value = value;
|
413
|
-
|
413
|
+
this.init(value);
|
414
|
+
}
|
415
|
+
init(value) {
|
416
|
+
for (let key in value) {
|
414
417
|
this.states[key] = createState(value[key]);
|
415
418
|
}
|
416
419
|
}
|
420
|
+
assign(value) {
|
421
|
+
for (let key in value) {
|
422
|
+
if (!this.states[key])
|
423
|
+
this.states[key] = createState(value[key]);
|
424
|
+
else
|
425
|
+
this.states[key].set(value[key]);
|
426
|
+
}
|
427
|
+
}
|
417
428
|
get(key) {
|
418
429
|
return this.states[key];
|
419
430
|
}
|
@@ -1089,15 +1100,23 @@ class RumiousModule {
|
|
1089
1100
|
class RumiousContext {
|
1090
1101
|
values;
|
1091
1102
|
events = {};
|
1103
|
+
states = {};
|
1092
1104
|
constructor(values) {
|
1093
1105
|
this.values = values;
|
1094
1106
|
}
|
1095
1107
|
set(key, value) {
|
1096
1108
|
this.values[key] = value;
|
1109
|
+
if (this.states[key])
|
1110
|
+
this.states[key].set(value);
|
1097
1111
|
}
|
1098
1112
|
get(key) {
|
1099
1113
|
return this.values[key];
|
1100
1114
|
}
|
1115
|
+
reactive(key) {
|
1116
|
+
if (!this.states[key])
|
1117
|
+
this.states[key] = createState(this.values[key]);
|
1118
|
+
return this.states[key];
|
1119
|
+
}
|
1101
1120
|
emit(event, ...args) {
|
1102
1121
|
const listeners = this.events[event];
|
1103
1122
|
if (listeners) {
|
package/dist/state/store.d.ts
CHANGED
@@ -6,6 +6,8 @@ export declare class RumiousStore<T extends {}> {
|
|
6
6
|
value: T;
|
7
7
|
states: RumiousStoreReactiveMap<T>;
|
8
8
|
constructor(value: T);
|
9
|
+
private init;
|
10
|
+
assign(value: T): void;
|
9
11
|
get<K extends keyof T>(key: K): RumiousState<T[K]>;
|
10
12
|
set(value: T): void;
|
11
13
|
map<U>(fn: <K extends keyof T>(state: RumiousState<T[K]>, key: K) => U): U[];
|