UNPKG

@zedux/core

Version:

A high-level, declarative, composable form of Redux

39 lines (38 loc) 1.66 kB
import { HierarchyConfig } from '../types.js'; import { HierarchyNode } from '../utils/types.js'; /** * Merges two hierarchies together. * * Uses head recursion to merge the leaf nodes first. This allows this step to * also find each node's reducer. (A node's children reducers need to exist * before its own reducer can) * * Destroys any no-longer-used resources in the oldTree. * * The resulting tree will always have the type of the newTree. * * Dynamically injects reducers and stores into the hierarchy or replaces the * hierarchy altogether. * * There are 4 types of nodes in this hierarchy: * - BRANCH - indicates a branch (non-leaf) node * - REDUCER - indicates a leaf node handled by this store * - STORE - indicates a leaf node handled by another store * - NULL - indicates a non-existent node, or node to be deleted * * BRANCH nodes will be deeply merged (recursively). * * All other nodes will be overwritten. */ export declare const mergeHierarchies: (oldTree: HierarchyNode | undefined, newTree: HierarchyNode, hierarchyConfig: HierarchyConfig) => HierarchyNode; /** * Deeply merges the new state tree into the old one. * * If this hydration contains new state for a child store, this parent store * will create the child store's state for it :O * * This means that mixing hierarchyConfigs is not supported, since only the * parent's hierarchyConfig will be respected during this merge. The child's * state will be full-hydrated with its new state after this merge. */ export declare const mergeStateTrees: (oldStateTree: any, newStateTree: any, hierarchyConfig: HierarchyConfig) => readonly [any, boolean];