MCPcopy Create free account
hub / github.com/sshwsfc/xadmin / block

Function block

packages/xadmin/src/block.js:4–25  ·  view source on GitHub ↗
(tag, props={})

Source from the content-addressed store, hash-verified

2import _ from 'lodash'
3
4const block = (tag, props={}) => {
5 const app = window.__app__
6
7 const blocks = app.get('blocks')
8 if(blocks[tag] !== undefined) {
9 const nodes = blocks[tag].reduce((prev, block) => {
10 const ret = block({ nodes: prev, ...props })
11 if(ret != undefined && ret != null && ret != prev) {
12 if(Array.isArray(ret)) {
13 prev = prev.concat(ret.map(c => React.cloneElement(c, props)))
14 } else if(React.isValidElement(ret)) {
15 prev.push(React.cloneElement(ret, props))
16 }
17 }
18 return prev
19 }, [])
20 if(nodes.length && nodes.filter(node => node !== null).length > 0) {
21 return nodes
22 }
23 }
24 return null
25}
26
27const Block = ({ name, children, ...props }) => {
28 const bs = block(name, props)

Callers 1

BlockFunction · 0.85

Calls 3

reduceMethod · 0.80
mapMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected