Skip to content

Commit

Permalink
Basic array support with apply patches
Browse files Browse the repository at this point in the history
  • Loading branch information
vladnicula committed Dec 16, 2023
2 parents 294bf1c + d71961b commit cda148e
Show file tree
Hide file tree
Showing 13 changed files with 1,119 additions and 2,182 deletions.
31 changes: 27 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,32 @@ export declare class MutationsManager {
mutationMaps: Map<ObjectTree, ProxyMapType<ObjectTree>>;
mutationDirtyPaths: Map<ObjectTree, Set<ProxyMutationObjectHandler<ObjectTree>>>;
mutationSelectorPointers: Map<ObjectTree, Array<SelectorTreeBranch>>;
mutationChagnePointers: Map<ObjectTree, MutationTreeNode>;
mutationChangePointers: Map<ObjectTree, MutationTreeNode>;
private getSubProxy;
startMutation(target: ObjectTree): void;
hasRoot(rootA: any): boolean;
commit(target: ObjectTree): JSONPatchEnhanced[];
mutate<T extends ObjectTree>(target: T, callback: (mutable: T) => unknown): JSONPatchEnhanced[] | undefined;
commit(target: ObjectTree): {
op: "replace" | "remove" | "add";
path: string;
value: unknown;
old?: unknown;
pathArray: string[];
}[];
mutate<T extends ObjectTree>(target: T, callback: (mutable: T) => unknown): {
op: "replace" | "remove" | "add";
path: string;
value: unknown;
old?: unknown;
pathArray: string[];
}[] | undefined;
}
export declare const mutate: <T extends object>(stateTree: T, callback: (mutable: T) => unknown) => JSONPatchEnhanced[] | undefined;
export declare const mutate: <T extends object>(stateTree: T, callback: (mutable: T) => unknown) => {
op: 'replace' | 'remove' | 'add';
path: string;
value: unknown;
old?: unknown;
pathArray: string[];
}[] | undefined;
export declare const autorun: <T extends object>(stateTree: T, callback: (observable: T, patches?: JSONPatchEnhanced[] | undefined) => unknown) => () => void;
/**
* When working with domain objects, it's probably best to have a
Expand Down Expand Up @@ -57,12 +75,14 @@ export declare class ProxyMutationObjectHandler<T extends object> {
readonly selectorPointerArray: Array<SelectorTreeBranch>;
readonly writeSelectorPointerArray: Array<SelectorTreeBranch>;
mutationNode: MutationTreeNode;
incOpCount: () => number;
constructor(params: {
mutationNode: MutationTreeNode;
target: T;
selectorPointerArray: Array<SelectorTreeBranch>;
dirtyPaths: Set<ProxyMutationObjectHandler<ObjectTree>>;
proxyfyAccess: ProxyAccessFN;
incOpCount: () => number;
});
get<K extends keyof T>(target: T, prop: K): any;
set<K extends keyof T>(target: T, prop: K, value: T[K]): boolean;
Expand Down Expand Up @@ -97,12 +117,14 @@ export declare class ProxyMutationArrayHandler<T extends Array<any>> {
readonly selectorPointerArray: Array<SelectorTreeBranch>;
readonly writeSelectorPointerArray: Array<SelectorTreeBranch>;
mutationNode: MutationTreeNode;
incOpCount: () => number;
constructor(params: {
mutationNode: MutationTreeNode;
target: T;
selectorPointerArray: Array<SelectorTreeBranch>;
dirtyPaths: Set<ProxyMutationArrayHandler<T>>;
proxyfyAccess: ProxyAccessFN;
incOpCount: () => number;
});
get<K extends keyof T>(target: T, prop: K): any;
set<K extends keyof T>(target: T, prop: K, value: T[K]): boolean;
Expand Down Expand Up @@ -133,4 +155,5 @@ export declare const select: <T extends object, MP extends SelectorMappingBase<T
dispose: () => void;
};
export declare const inversePatch: (patch: JSONPatchEnhanced) => JSONPatchEnhanced;
export declare const LIB_VERSION = "2.0.6beta";
export {};
2 changes: 1 addition & 1 deletion dist/index.main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.module.js

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions dist/mutation-map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ export interface MutationTreeNodeWithReplace {
old: unknown;
/** new value is again, probably falsy, but still exists */
new: unknown;
opCount: number;
}
export interface MutationTreeNodeWithRemove {
/** operation remove old contains old value */
op: "remove";
/** old value ca be fasly, but still exists */
old: unknown;
opCount: number;
}
export interface MutationTreeNodeWithAdd {
/** operation add only contains a new value */
op: "add";
/** new value is can be falsy, but still exists */
new: any;
opCount: number;
}
export declare type MutationTreeNode = ({} | MutationTreeNodeWithReplace | MutationTreeNodeWithRemove | MutationTreeNodeWithAdd) & {
k: string | number;
Expand All @@ -44,6 +47,14 @@ export declare type MutationTreeNode = ({} | MutationTreeNodeWithReplace | Mutat
*/
export declare const getParentWithOperation: (mutationNode: MutationTreeNode) => [MutationTreeNode, string[]] | null;
export declare const makeAndGetChildPointer: (mutationNode: MutationTreeNode, prop: string | number) => MutationTreeNode;
export declare const createMutaitonInMutationTree: (mutationNode: MutationTreeNode, oldValue: unknown, newValue: unknown) => void;
export declare const getPatchesFromMutationTree: (mutationNode: MutationTreeNode) => JSONPatchEnhanced[];
export declare const accumulatePatchesFromMutationTree: (mutationNode: MutationTreeNode, acc: JSONPatchEnhanced[], pathArray?: string[]) => void;
export declare const createMutaitonInMutationTree: (mutationNode: MutationTreeNode, oldValue: unknown, newValue: unknown, opCount: number) => void;
export declare const getPatchesFromMutationTree: (mutationNode: MutationTreeNode) => {
op: "replace" | "remove" | "add";
path: string;
value: unknown;
old?: unknown;
pathArray: string[];
}[];
export declare const accumulatePatchesFromMutationTree: (mutationNode: MutationTreeNode, acc: Array<JSONPatchEnhanced & {
opCount: number;
}>, pathArray?: string[]) => void;
Loading

0 comments on commit cda148e

Please sign in to comment.