r-state-tree 0.4.7 → 0.6.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.
@@ -25,6 +25,6 @@ export declare class StoreAdministration<StoreType extends Store = Store> extend
25
25
  getContextValue<T>(contextId: symbol, provideSymbol: symbol, defaultValue: T | undefined, hasDefault: boolean): T;
26
26
  private lookupContextValue;
27
27
  reaction<T>(track: () => T, callback: (a: T) => void): () => void;
28
- mount(parent?: StoreAdministration | null): void;
28
+ mount(parent?: StoreAdministration | null, childName?: PropertyKey): void;
29
29
  unmount(): void;
30
30
  }
@@ -0,0 +1 @@
1
+ export declare function toObservableTree<T>(value: T): T;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type Store from "./store/Store";
2
2
  import type Model from "./model/Model";
3
+ import type { Signal } from "@preact/signals-core";
3
4
  export type StoreElement = {
4
5
  Type: new (...args: unknown[]) => Store;
5
6
  props: Props;
@@ -41,7 +42,6 @@ export declare enum StoreCfgTypes {
41
42
  model = "model"
42
43
  }
43
44
  export declare enum ObservableCfgTypes {
44
- observable = "observable",
45
45
  computed = "computed"
46
46
  }
47
47
  export type ConfigurationTypes = CommonCfgTypes | ModelCfgTypes | StoreCfgTypes | ObservableCfgTypes;
@@ -53,7 +53,10 @@ export type ConfigurationType = {
53
53
  export type ModelConfiguration<T> = Record<PropertyKey, ConfigurationType>;
54
54
  export type StoreConfiguration<T> = Record<PropertyKey, ConfigurationType>;
55
55
  export type Configuration<T> = ModelConfiguration<T> | StoreConfiguration<T>;
56
- type SnapshotValue<T> = T extends Model ? Snapshot<T> : T extends Array<infer R> ? R extends Model ? Array<Snapshot<R>> : T : T;
56
+ type NonSnapshotable = Map<unknown, unknown> | Set<unknown> | WeakMap<object, unknown> | WeakSet<object> | RegExp | Error | Promise<unknown>;
57
+ export type SnapshotValue<T> = T extends bigint | symbol | Function ? never : T extends NonSnapshotable ? never : T extends Signal<infer U> ? SnapshotValue<U> : T extends Model ? Snapshot<T> : T extends Date ? string : T extends Array<infer R> ? R extends Model ? Array<Snapshot<R>> : Array<SnapshotValue<R>> : T extends object ? {
58
+ [K in keyof T]: SnapshotValue<T[K]>;
59
+ } : T;
57
60
  export type Snapshot<T extends Model = Model> = {
58
61
  [K in keyof T]?: T[K] extends infer U ? U extends Model | Model[] ? SnapshotValue<U> | null : U extends null | undefined ? null : SnapshotValue<Exclude<U, null | undefined>> | null : never;
59
62
  };
@@ -75,6 +78,5 @@ export declare const modelRefType: ((childType: Function) => ConfigurationType)
75
78
  };
76
79
  export declare const idType: ConfigurationType;
77
80
  export declare const modelType: ConfigurationType;
78
- export declare const observableType: ConfigurationType;
79
81
  export declare const computedType: ConfigurationType;
80
82
  export {};
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ModelConfiguration } from "./types";
2
2
  export declare function getPropertyDescriptor(obj: object, key: PropertyKey): PropertyDescriptor | undefined;
3
3
  export declare function getParentConstructor(Ctor: Function | undefined): Function | undefined;
4
- export declare function clone<T>(val: T): T;
4
+ export declare function clone<T>(val: T, path?: string): T;
5
5
  export declare function getDiff<T extends object>(o1: T, o2: T, getConfig: (snapshot: object) => ModelConfiguration<unknown> | undefined): Partial<T> | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "r-state-tree",
3
- "version": "0.4.7",
3
+ "version": "0.6.0",
4
4
  "description": "reactive state management library",
5
5
  "main": "dist/r-state-tree.cjs",
6
6
  "module": "dist/r-state-tree.js",