Skip to content

feat: add support for more component types (Custom Element classes and D3 functions) #29

@pemrouz

Description

@pemrouz

Besides having both stateless and stateful components as pure functions of data, it would be good to also add support for the new Custom Elements style classes and the more traditional D3 components. D3 components should be straightforward given it was the source of the inspiration for the current components. Classes would be expected to have a similar declarative render function (draw) but also allows developers to more neatly setup other methods/accessors/lifecycle hooks/etc. This should also improve interop.

Classical D3 Component

function chart() {
  var width = 720, // default width
      height = 80; // default height

  function my() {
    // generate chart here, using `width` and `height`
  }

  my.width = function(value) {
    if (!arguments.length) return width;
    width = value;
    return my;
  };

  my.height = function(value) {
    if (!arguments.length) return height;
    height = value;
    return my;
  };

  return my;
}

Custom Element Class

class MyComponent extends HTMLElement {
  // can move name and other meta data here..
  name: 'my-component' 

  get width(){ 
    return this._width
  }

  set width(value){ 
    this._width = value
  }

  draw(node, data) {
    // update node
    jsx(node)`
      ...
    `
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions