rumious 2.1.2 → 2.1.4

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.
@@ -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
@@ -313,6 +313,11 @@ class RumiousState {
313
313
  state: this
314
314
  });
315
315
  }
316
+ entries() {
317
+ if (this.value && typeof this.value === "object")
318
+ return Object.entries(this.value);
319
+ return [];
320
+ }
316
321
  }
317
322
  function createState(value) {
318
323
  return new RumiousState(value);
@@ -1100,15 +1105,23 @@ class RumiousModule {
1100
1105
  class RumiousContext {
1101
1106
  values;
1102
1107
  events = {};
1108
+ states = {};
1103
1109
  constructor(values) {
1104
1110
  this.values = values;
1105
1111
  }
1106
1112
  set(key, value) {
1107
1113
  this.values[key] = value;
1114
+ if (this.states[key])
1115
+ this.states[key].set(value);
1108
1116
  }
1109
1117
  get(key) {
1110
1118
  return this.values[key];
1111
1119
  }
1120
+ reactive(key) {
1121
+ if (!this.states[key])
1122
+ this.states[key] = createState(this.values[key]);
1123
+ return this.states[key];
1124
+ }
1112
1125
  emit(event, ...args) {
1113
1126
  const listeners = this.events[event];
1114
1127
  if (listeners) {
@@ -11,6 +11,7 @@ export declare class RumiousState<T> {
11
11
  toJSON(): string;
12
12
  equal(value: T): boolean;
13
13
  trigger(): void;
14
+ entries(): [any, any][];
14
15
  }
15
16
  export declare function createState<T>(value: T): RumiousState<T>;
16
17
  type StateBindFor<M> = RumiousStateBind<RumiousState<M>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rumious",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",