UNPKG

@zedux/core

Version:

A high-level, declarative, composable form of Redux

57 lines (52 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.size = exports.set = exports.iterate = exports.isNode = exports.get = exports.create = exports.clone = void 0; const isPlainObject_1 = require("../api/isPlainObject"); /** The default method for cloning state tree nodes This does not have to create a deep copy. In fact, it probably shouldn't. */ const clone = (node) => (Object.assign({}, node)); exports.clone = clone; /** The default method for creating state tree nodes Should return an empty node. */ const create = () => ({}); exports.create = create; /** The default method for retrieving the value of a property on the state tree. */ const get = (node, key) => node[key]; exports.get = get; /** The default method for determining if something is a state tree node */ exports.isNode = isPlainObject_1.isPlainObject; /** The default method for iterating over the properties of a state tree node. Should call `callback` with each key-value pair. */ const iterate = (node, callback) => { Object.entries(node).forEach(([key, val]) => callback(key, val)); }; exports.iterate = iterate; /** 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. */ const set = (node, key, val) => { node[key] = val; return node; }; exports.set = set; /** The default method for finding the size of a state tree node. */ const size = (node) => Object.keys(node).length; exports.size = size;