code: function nextLevel(selection, data) {
      if (!selection.select('.childlist').size()) {
        selection.append('ul')
          .classed('childlist', true)
          .style('list-style-type', 'none');
      }
      const items = selection.select('.childlist')
        .selectAll('li')
          .data(data, keyDef);
      items.exit().remove();
      items.enter()
        .append('li')
          .each(function (d) {
            d3.select(this).call(nodeEnterFactory, d.data);
          })
        .merge(items)
          .each(function (d) {
            const node = d3.select(this);
            node.call(nodeMergeFactory, d.data);
            if (d.hasOwnProperty('children')) {
              node.call(nextLevel, d.children)
                .select('.arrow')
                  .text(d => d.depth - 1 >= defaultLevel ? '▶ ' : '▼ ')
                  .on('click', function () {  // Collapse on click
                    const childList = node.select('.childlist');
                    const expanded = childList.style('display') !== 'none';
                    d3.select(this).text(expanded ? '▶ ' : '▼ ');
                    childList.style('display', expanded ? 'none' : 'inherit');
                  });
              node.select('.childlist')
                  .style('display',
                    d => d.depth - 1 >= defaultLevel ? 'none' : 'inherit');
            } else {
              node.select('.childlist').remove();
            }
          });
    }
docs: Recursively append child nodes