import { select, local } from "d3-selection";
var myLocal = local(),
    noop = function (){};

export default function (tagName, className){
  var create = noop,
      render = noop,
      destroy = noop,
      myCreate = function (){
        var my = myLocal.set(this, {
          selection: select(this),
          state: {},
          render: noop
        });
        create(my.selection, function setState(state){
          Object.assign(my.state, state);
          my.render();
        });
        my.render = function (){
          render(my.selection, my.props, my.state);
        };
      },
      myRender = function (props){
        var my = myLocal.get(this);
        my.props = props;
        my.render();
      },
      myDestroy = function (props){
        destroy(myLocal.get(this).state);
      },
      selector = className ? "." + className : tagName;

  function component(selection, props){
    var components = selection.selectAll(selector)
      .data(Array.isArray(props) ? props : [props]);
    components
      .enter().append(tagName)
        .attr("class", className)
        .each(myCreate)
      .merge(components)
        .each(myRender);
    components
      .exit()
        .each(myDestroy)
        .remove();
  }

  component.render = function(_) { render = _; return component; };
  component.create = function(_) { create = _; return component; };
  component.destroy = function(_) { destroy = _; return component; };

  return component;
};

@@ -866,21 +866,15 @@
 Name
-;%0A%0A  function
+,%0A     
  com
@@ -879,16 +879,27 @@
 omponent
+ = function
 (selecti
@@ -906,24 +906,28 @@
 on, props)%7B%0A
+    
     var comp
@@ -971,16 +971,20 @@
 )%0A      
+    
 .data(Ar
@@ -1022,16 +1022,20 @@
 rops%5D);%0A
+    
     comp
@@ -1047,16 +1047,20 @@
 s%0A      
+    
 .enter()
@@ -1072,24 +1072,28 @@
 nd(tagName)%0A
+    
         .att
@@ -1114,32 +1114,36 @@
 ssName)%0A        
+    
 .each(myCreate)%0A
@@ -1148,16 +1148,20 @@
 )%0A      
+    
 .merge(c
@@ -1171,32 +1171,36 @@
 onents)%0A        
+    
 .each(myRender);
@@ -1200,24 +1200,28 @@
 ender);%0A    
+    
 components%0A 
@@ -1215,24 +1215,28 @@
  components%0A
+    
       .exit(
@@ -1237,32 +1237,36 @@
 .exit()%0A        
+    
 .each(myDestroy)
@@ -1274,16 +1274,20 @@
         
+    
 .remove(
@@ -1295,10 +1295,14 @@
 ;%0A  
-%7D%0A
+    %7D;
 %0A  c
@@ -1426,32 +1426,32 @@
 n component; %7D;%0A
+
   component.dest
@@ -1504,17 +1504,16 @@
 ent; %7D;%0A
-%0A
   return

Switch back to var syntax for all functions