mobx-state-tree 3.14.1 → 3.17.2

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.
@@ -17,7 +17,7 @@ export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (a
17
17
  * Middleware can be used to intercept any action is invoked on the subtree where it is attached.
18
18
  * If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
19
19
  *
20
- * For more details, see the [middleware docs](../middleware.md)
20
+ * For more details, see the [middleware docs](concepts/middleware.md)
21
21
  *
22
22
  * @param target Node to apply the middleware to.
23
23
  * @param middleware Middleware to apply.
@@ -1,30 +1,63 @@
1
- /** @hidden */
2
- declare const $flowYield: unique symbol;
3
- /** @hidden */
4
- export interface FlowYield {
5
- [$flowYield]: undefined;
6
- }
7
- /** @hidden */
8
- declare const $flowReturn: unique symbol;
9
- /** @hidden */
10
- export interface FlowReturn<T> {
11
- [$flowReturn]: T;
12
- }
13
- /** @hidden */
14
- export declare type FlowReturnType<R> = IfAllAreFlowYieldThenVoid<R extends FlowReturn<infer FR> ? FR extends Promise<infer FRP> ? FRP : FR : R extends Promise<any> ? FlowYield : R>;
15
- /** @hidden */
16
- export declare type IfAllAreFlowYieldThenVoid<R> = Exclude<R, FlowYield> extends never ? void : Exclude<R, FlowYield>;
17
1
  /**
18
- * See [asynchronous actions](https://github.com/mobxjs/mobx-state-tree/blob/master/docs/async-actions.md).
2
+ * @hidden
3
+ */
4
+ export declare type FlowReturn<R> = R extends Promise<infer T> ? T : R;
5
+ /**
6
+ * See [asynchronous actions](concepts/async-actions.md).
19
7
  *
20
8
  * @returns The flow as a promise.
21
9
  */
22
- export declare function flow<R, Args extends any[]>(generator: (...args: Args) => IterableIterator<R>): (...args: Args) => Promise<FlowReturnType<R>>;
10
+ export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<Promise<any>, R, any>): (...args: Args) => Promise<FlowReturn<R>>;
23
11
  /**
24
- * Used for TypeScript to make flows that return a promise return the actual promise result.
12
+ * @deprecated Not needed since TS3.6.
13
+ * Used for TypeScript to make flows that return a promise return the actual promise result.
25
14
  *
26
15
  * @param val
27
16
  * @returns
28
17
  */
29
- export declare function castFlowReturn<T>(val: T): FlowReturn<T>;
30
- export {};
18
+ export declare function castFlowReturn<T>(val: T): T;
19
+ /**
20
+ * @experimental
21
+ * experimental api - might change on minor/patch releases
22
+ *
23
+ * Convert a promise-returning function to a generator-returning one.
24
+ * This is intended to allow for usage of `yield*` in async actions to
25
+ * retain the promise return type.
26
+ *
27
+ * Example:
28
+ * ```ts
29
+ * function getDataAsync(input: string): Promise<number> { ... }
30
+ * const getDataGen = toGeneratorFunction(getDataAsync);
31
+ *
32
+ * const someModel.actions(self => ({
33
+ * someAction: flow(function*() {
34
+ * // value is typed as number
35
+ * const value = yield* getDataGen("input value");
36
+ * ...
37
+ * })
38
+ * }))
39
+ * ```
40
+ */
41
+ export declare function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => Promise<R>): (...args: Args) => Generator<Promise<R>, R, R>;
42
+ /**
43
+ * @experimental
44
+ * experimental api - might change on minor/patch releases
45
+ *
46
+ * Convert a promise to a generator yielding that promise
47
+ * This is intended to allow for usage of `yield*` in async actions to
48
+ * retain the promise return type.
49
+ *
50
+ * Example:
51
+ * ```ts
52
+ * function getDataAsync(input: string): Promise<number> { ... }
53
+ *
54
+ * const someModel.actions(self => ({
55
+ * someAction: flow(function*() {
56
+ * // value is typed as number
57
+ * const value = yield* toGenerator(getDataAsync("input value"));
58
+ * ...
59
+ * })
60
+ * }))
61
+ * ```
62
+ */
63
+ export declare function toGenerator<R>(p: Promise<R>): Generator<Promise<R>, R, R>;
@@ -1,4 +1,4 @@
1
- import { IAnyStateTreeNode, IType, IAnyModelType, IStateTreeNode, IJsonPatch, IDisposer, IAnyType, ReferenceIdentifier, TypeOfValue, IActionContext } from "../internal";
1
+ import { IAnyStateTreeNode, IType, IAnyModelType, IStateTreeNode, IJsonPatch, IDisposer, IAnyType, ReferenceIdentifier, TypeOfValue, IActionContext, IAnyComplexType } from "../internal";
2
2
  /** @hidden */
3
3
  export declare type TypeOrStateTreeNodeToStateTreeNode<T extends IAnyType | IAnyStateTreeNode> = T extends IType<any, any, infer TT> ? TT & IStateTreeNode<T> : T;
4
4
  /**
@@ -7,7 +7,7 @@ export declare type TypeOrStateTreeNodeToStateTreeNode<T extends IAnyType | IAny
7
7
  * @param object
8
8
  * @returns
9
9
  */
10
- export declare function getType(object: IAnyStateTreeNode): IAnyType;
10
+ export declare function getType(object: IAnyStateTreeNode): IAnyComplexType;
11
11
  /**
12
12
  * Returns the _declared_ type of the given sub property of an object, array or map.
13
13
  * In the case of arrays and maps the property name is optional and will be ignored.
@@ -171,7 +171,7 @@ export declare function hasParent(target: IAnyStateTreeNode, depth?: number): bo
171
171
  * @param depth How far should we look upward? 1 by default.
172
172
  * @returns
173
173
  */
174
- export declare function getParent<IT extends IAnyStateTreeNode | IAnyType>(target: IAnyStateTreeNode, depth?: number): TypeOrStateTreeNodeToStateTreeNode<IT>;
174
+ export declare function getParent<IT extends IAnyStateTreeNode | IAnyComplexType>(target: IAnyStateTreeNode, depth?: number): TypeOrStateTreeNodeToStateTreeNode<IT>;
175
175
  /**
176
176
  * Given a model instance, returns `true` if the object has a parent of given type, that is, is part of another object, map or array
177
177
  *
@@ -179,7 +179,7 @@ export declare function getParent<IT extends IAnyStateTreeNode | IAnyType>(targe
179
179
  * @param type
180
180
  * @returns
181
181
  */
182
- export declare function hasParentOfType(target: IAnyStateTreeNode, type: IAnyType): boolean;
182
+ export declare function hasParentOfType(target: IAnyStateTreeNode, type: IAnyComplexType): boolean;
183
183
  /**
184
184
  * Returns the target's parent of a given type, or throws.
185
185
  *
@@ -187,7 +187,7 @@ export declare function hasParentOfType(target: IAnyStateTreeNode, type: IAnyTyp
187
187
  * @param type
188
188
  * @returns
189
189
  */
190
- export declare function getParentOfType<IT extends IAnyType>(target: IAnyStateTreeNode, type: IT): IT["Type"];
190
+ export declare function getParentOfType<IT extends IAnyComplexType>(target: IAnyStateTreeNode, type: IT): IT["Type"];
191
191
  /**
192
192
  * Given an object in a model tree, returns the root object of that tree.
193
193
  *
@@ -197,7 +197,7 @@ export declare function getParentOfType<IT extends IAnyType>(target: IAnyStateTr
197
197
  * @param target
198
198
  * @returns
199
199
  */
200
- export declare function getRoot<IT extends IAnyType | IAnyStateTreeNode>(target: IAnyStateTreeNode): TypeOrStateTreeNodeToStateTreeNode<IT>;
200
+ export declare function getRoot<IT extends IAnyComplexType | IAnyStateTreeNode>(target: IAnyStateTreeNode): TypeOrStateTreeNodeToStateTreeNode<IT>;
201
201
  /**
202
202
  * Returns the path of the given object in the model tree
203
203
  *
@@ -237,7 +237,7 @@ export declare function resolvePath(target: IAnyStateTreeNode, path: string): an
237
237
  * @param identifier
238
238
  * @returns
239
239
  */
240
- export declare function resolveIdentifier<IT extends IAnyType>(type: IT, target: IAnyStateTreeNode, identifier: ReferenceIdentifier): IT["Type"] | undefined;
240
+ export declare function resolveIdentifier<IT extends IAnyModelType>(type: IT, target: IAnyStateTreeNode, identifier: ReferenceIdentifier): IT["Type"] | undefined;
241
241
  /**
242
242
  * Returns the identifier of the target node.
243
243
  * This is the *string normalized* identifier, which might not match the type of the identifier attribute
@@ -1 +1,17 @@
1
- export {};
1
+ /**
2
+ * @hidden
3
+ */
4
+ export declare enum Hook {
5
+ afterCreate = "afterCreate",
6
+ afterAttach = "afterAttach",
7
+ afterCreationFinalization = "afterCreationFinalization",
8
+ beforeDetach = "beforeDetach",
9
+ beforeDestroy = "beforeDestroy"
10
+ }
11
+ export interface IHooks {
12
+ [Hook.afterCreate]?: () => void;
13
+ [Hook.afterAttach]?: () => void;
14
+ [Hook.beforeDetach]?: () => void;
15
+ [Hook.beforeDestroy]?: () => void;
16
+ }
17
+ export declare type IHooksGetter<T> = (self: T) => IHooks;
@@ -1,4 +1,4 @@
1
- import { IAnyType } from "../../internal";
1
+ import { IAnyType, STNValue, Instance, IAnyComplexType } from "../../internal";
2
2
  /** @hidden */
3
3
  declare const $stateTreeNodeType: unique symbol;
4
4
  /**
@@ -14,7 +14,7 @@ export declare type TypeOfValue<T extends IAnyStateTreeNode> = T extends IStateT
14
14
  * Represents any state tree node instance.
15
15
  * @hidden
16
16
  */
17
- export interface IAnyStateTreeNode extends IStateTreeNode<IAnyType> {
17
+ export interface IAnyStateTreeNode extends STNValue<any, IAnyType> {
18
18
  }
19
19
  /**
20
20
  * Returns true if the given value is a node in a state tree.
@@ -24,5 +24,5 @@ export interface IAnyStateTreeNode extends IStateTreeNode<IAnyType> {
24
24
  * @param value
25
25
  * @returns true if the value is a state tree node.
26
26
  */
27
- export declare function isStateTreeNode<IT extends IAnyType = IAnyType>(value: any): value is IStateTreeNode<IT>;
27
+ export declare function isStateTreeNode<IT extends IAnyComplexType = IAnyComplexType>(value: any): value is STNValue<Instance<IT>, IT>;
28
28
  export {};
@@ -1,5 +1,6 @@
1
1
  import { IValidationContext, IValidationResult, IStateTreeNode, ModelPrimitive } from "../../internal";
2
2
  /**
3
+ * A state tree node value.
3
4
  * @hidden
4
5
  */
5
6
  export declare type STNValue<T, IT extends IAnyType> = T extends object ? T & IStateTreeNode<IT> : T;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { IModelType, IAnyModelType, IDisposer, IMSTMap, IMapType, IMSTArray, IArrayType, IType, IAnyType, ModelPrimitive, ISimpleType, IComplexType, IAnyComplexType, IReferenceType, _CustomCSProcessor, _CustomOrOther, _CustomJoin, _NotCustomized, typecheck, escapeJsonPath, unescapeJsonPath, joinJsonPath, splitJsonPath, IJsonPatch, IReversibleJsonPatch, decorate, addMiddleware, IMiddlewareEvent, IActionTrackingMiddleware2Call, IMiddlewareHandler, IMiddlewareEventType, IActionTrackingMiddlewareHooks, IActionTrackingMiddleware2Hooks, process, isStateTreeNode, IStateTreeNode, IAnyStateTreeNode, flow, castFlowReturn, applyAction, onAction, IActionRecorder, ISerializedActionCall, recordActions, createActionTrackingMiddleware, createActionTrackingMiddleware2, setLivelinessChecking, getLivelinessChecking, LivelinessMode, setLivelynessChecking, // to be deprecated
2
2
  LivelynessMode, // to be deprecated
3
- ModelSnapshotType, ModelCreationType, ModelSnapshotType2, ModelCreationType2, ModelInstanceType, ModelInstanceTypeProps, ModelPropertiesDeclarationToProperties, ModelProperties, ModelPropertiesDeclaration, ModelActions, ITypeUnion, CustomTypeOptions, UnionOptions, Instance, SnapshotIn, SnapshotOut, SnapshotOrInstance, TypeOrStateTreeNodeToStateTreeNode, UnionStringArray, getType, getChildType, onPatch, onSnapshot, applyPatch, IPatchRecorder, recordPatches, protect, unprotect, isProtected, applySnapshot, getSnapshot, hasParent, getParent, hasParentOfType, getParentOfType, getRoot, getPath, getPathParts, isRoot, resolvePath, resolveIdentifier, getIdentifier, tryResolve, getRelativePath, clone, detach, destroy, isAlive, addDisposer, getEnv, walk, IModelReflectionData, IModelReflectionPropertiesData, IMaybeIType, IMaybe, IMaybeNull, IOptionalIType, OptionalDefaultValueOrFunction, ValidOptionalValue, ValidOptionalValues, getMembers, getPropertyMembers, TypeOfValue, cast, castToSnapshot, castToReferenceSnapshot, isType, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isReferenceType, isRefinementType, isUnionType, tryReference, isValidReference, OnReferenceInvalidated, OnReferenceInvalidatedEvent, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, ReferenceIdentifier, ISnapshotProcessor, ISnapshotProcessors, getNodeId, IActionContext, getRunningActionContext, isActionContextChildOf, isActionContextThisOrChildOf, types } from "./internal";
3
+ ModelSnapshotType, ModelCreationType, ModelSnapshotType2, ModelCreationType2, ModelInstanceType, ModelInstanceTypeProps, ModelPropertiesDeclarationToProperties, ModelProperties, ModelPropertiesDeclaration, ModelActions, ITypeUnion, CustomTypeOptions, UnionOptions, Instance, SnapshotIn, SnapshotOut, SnapshotOrInstance, TypeOrStateTreeNodeToStateTreeNode, UnionStringArray, getType, getChildType, onPatch, onSnapshot, applyPatch, IPatchRecorder, recordPatches, protect, unprotect, isProtected, applySnapshot, getSnapshot, hasParent, getParent, hasParentOfType, getParentOfType, getRoot, getPath, getPathParts, isRoot, resolvePath, resolveIdentifier, getIdentifier, tryResolve, getRelativePath, clone, detach, destroy, isAlive, addDisposer, getEnv, walk, IModelReflectionData, IModelReflectionPropertiesData, IMaybeIType, IMaybe, IMaybeNull, IOptionalIType, OptionalDefaultValueOrFunction, ValidOptionalValue, ValidOptionalValues, getMembers, getPropertyMembers, TypeOfValue, cast, castToSnapshot, castToReferenceSnapshot, isType, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isReferenceType, isRefinementType, isUnionType, tryReference, isValidReference, OnReferenceInvalidated, OnReferenceInvalidatedEvent, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, ReferenceIdentifier, ISnapshotProcessor, ISnapshotProcessors, getNodeId, IActionContext, getRunningActionContext, isActionContextChildOf, isActionContextThisOrChildOf, types, toGeneratorFunction, toGenerator } from "./internal";