Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/client/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -145,5 +146,7 @@ export default (config) => {
isPausedNested,
pauseNested,
unpauseNested,
allLeaves: allPathLeaves,
anyLeaves: anyPathLeaves,
}
}
8 changes: 7 additions & 1 deletion packages/client/src/node.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -32,6 +32,8 @@ export let internalStateKeys = [
'forceReplaceResponse',
'expand',
'collapse',
'someError',
'everyPaused',
]

export let autoKey = (x) => F.compactJoin('-', [x.field, x.type]) || 'node'
Expand All @@ -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),
}),
})
})

Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/util/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))