UNPKG

@platform/state

Version:

A small, simple, strongly typed, [rx/observable] state-machine.

38 lines (37 loc) 1.07 kB
import { TreeIdentity } from '../TreeIdentity'; import { TreeQuery } from '../TreeQuery'; const query = TreeQuery.create; const id = TreeIdentity; export const helpers = { id, isInstance(input) { return input === null || typeof input !== 'object' ? false : input._kind === 'TreeState'; }, props(of, fn) { of.props = of.props || {}; if (typeof fn === 'function') { fn(of.props); } return of.props; }, children(of, fn) { const children = (of.children = of.children || []); if (typeof fn === 'function') { fn(children); } return of.children; }, ensureNamespace(root, namespace) { query(root).walkDown((e) => { if (!id.hasNamespace(e.node.id)) { e.node.id = id.format(namespace, e.node.id); } else { const res = id.parse(e.node.id); if (res.namespace !== namespace) { e.skip(); } } }); }, };