| 32 | |
| 33 | // Recursive component |
| 34 | const Node: Component<NodeType> = props => { |
| 35 | let [childrenProps, nodeProps] = splitProps(props, ['children']) |
| 36 | // To store local component signals |
| 37 | type nodeSignalsType = { |
| 38 | parents: Array<number> |
| 39 | url: Array<string> |
| 40 | } |
| 41 | const [nodeSignals, setNodeSignals] = createStore<nodeSignalsType>({ |
| 42 | parents: nodeProps?.parents ? nodeProps?.parents : [], |
| 43 | url: genNodeUrl(nodeProps), |
| 44 | }) |
| 45 | |
| 46 | const addNode = useContext(RecursiveContext) |
| 47 | |
| 48 | return ( |
| 49 | <div style={{ |
| 50 | "border": "1px solid #1e293b", |
| 51 | "border-radius": "8px", |
| 52 | "padding": "0.5rem", |
| 53 | "margin": "1rem", |
| 54 | "gap": "0.5rem" |
| 55 | }}> |
| 56 | <p>{nodeSignals.url.join(' > ')}</p> |
| 57 | <For each={childrenProps.children}> |
| 58 | {node => { |
| 59 | const childProps = mergeProps( |
| 60 | { |
| 61 | parents: [...nodeSignals.parents, nodeProps.id], |
| 62 | url: nodeSignals.url, |
| 63 | }, |
| 64 | node, |
| 65 | ) |
| 66 | return <Node {...childProps} /> |
| 67 | }} |
| 68 | </For> |
| 69 | <button |
| 70 | style={{ |
| 71 | "border-radius": "9999px", |
| 72 | "background-color": "#1e293b", |
| 73 | "color": "white", |
| 74 | }} |
| 75 | onClick={e => addNode(nodeProps.id, nodeSignals.parents)} |
| 76 | > |
| 77 | Add item |
| 78 | </button> |
| 79 | </div> |
| 80 | ) |
| 81 | } |
| 82 | |
| 83 | const RecursiveContext = createContext<(nodeId: number, parentsPath: number[]) => void>(() => {}) |
| 84 |
nothing calls this directly
no test coverage detected
searching dependent graphs…