diff --git a/packages/client/src/actions/index.js b/packages/client/src/actions/index.js index 08e74c7cb..04febe8a6 100644 --- a/packages/client/src/actions/index.js +++ b/packages/client/src/actions/index.js @@ -1,6 +1,6 @@ import _ from 'lodash/fp.js' import F from 'futil' -import { encode, Tree } from '../util/tree.js' +import { encode, Tree, anyLeaves, allLeaves } from '../util/tree.js' import { getTypeProp } from '../types.js' import wrap from './wrap.js' import { dedupeWalk } from '../node.js' @@ -129,8 +129,9 @@ export default (config) => { let pauseNested = (path) => mutateNested(path, { paused: true }) let unpauseNested = (path) => mutateNested(path, { paused: false }) - let nodeLeaves = _.flow(getNode, Tree.leaves) - let isPausedNested = _.flow(nodeLeaves, _.every('paused')) + let anyPathLeaves = (path, fn) => anyLeaves(fn, getNode(path)) + let allPathLeaves = (path, fn) => allLeaves(fn, getNode(path)) + let isPausedNested = (path) => allPathLeaves(path, 'paused') return { add, @@ -145,5 +146,7 @@ export default (config) => { isPausedNested, pauseNested, unpauseNested, + allLeaves: allPathLeaves, + anyLeaves: anyPathLeaves, } } diff --git a/packages/client/src/node.js b/packages/client/src/node.js index 5f22b2015..731b7c7e1 100644 --- a/packages/client/src/node.js +++ b/packages/client/src/node.js @@ -1,6 +1,6 @@ import _ from 'lodash/fp.js' import F from 'futil' -import { Tree, encode } from './util/tree.js' +import { Tree, encode, anyLeaves, allLeaves } from './util/tree.js' import { runTypeFunction, runTypeFunctionOrDefault, @@ -32,6 +32,8 @@ export let internalStateKeys = [ 'forceReplaceResponse', 'expand', 'collapse', + 'someError', + 'everyPaused', ] export let autoKey = (x) => F.compactJoin('-', [x.field, x.type]) || 'node' @@ -50,6 +52,10 @@ export let initNode = _.curry((actionProps, dedupe, parentPath, node) => { ..._.omit(_.keys(node), snapshot(getTypeProp(types, 'defaults', node))), key, path: [...parentPath, key], + ...(node.children && { + someError: () => anyLeaves('error', node), + everyPaused: () => allLeaves('paused', node), + }), }) }) diff --git a/packages/client/src/util/tree.js b/packages/client/src/util/tree.js index d00207669..bd1bc19a4 100644 --- a/packages/client/src/util/tree.js +++ b/packages/client/src/util/tree.js @@ -28,3 +28,6 @@ export let postWalkBranches = (fn) => if (Tree.traverse(node)) fn(node, ...args) } ) + +export let anyLeaves = _.curry((fn, node) => _.some(fn, Tree.leaves(node))) +export let allLeaves = _.curry((fn, node) => _.every(fn, Tree.leaves(node)))