@zedux/core
Version:
A high-level, declarative, composable form of Redux
48 lines (43 loc) • 1.24 kB
JavaScript
import { isPlainObject } from '../api/isPlainObject.js';
/**
The default method for cloning state tree nodes
This does not have to create a deep copy.
In fact, it probably shouldn't.
*/
export const clone = (node) => (Object.assign({}, node));
/**
The default method for creating state tree nodes
Should return an empty node.
*/
export const create = () => ({});
/**
The default method for retrieving the value of a property on
the state tree.
*/
export const get = (node, key) => node[key];
/**
The default method for determining if something is a state tree node
*/
export const isNode = isPlainObject;
/**
The default method for iterating over the properties of a state tree
node.
Should call `callback` with each key-value pair.
*/
export const iterate = (node, callback) => {
Object.entries(node).forEach(([key, val]) => callback(key, val));
};
/**
The default method for setting the value of a property on the
state tree.
This can be mutating.
Zedux promises to never abuse this power.
*/
export const set = (node, key, val) => {
node[key] = val;
return node;
};
/**
The default method for finding the size of a state tree node.
*/
export const size = (node) => Object.keys(node).length;