Skip to content

smallhelm/virtual-dom-closure-widget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

virtual-dom-closure-widget

Make virtual-dom widgets by using a function closure that persists it's local state between renders.

Example

Check out example.js

To run it clone this repository then run

$ npm i && npm start

It will give you localhost url to open in your browser and see it running.

API

var mkWidget = require("virtual-dom-closure-widget");

var MyWidgetThing = mkWidget(function(props){

  //This code executes the first time a widget is mounted (i.e. Widget "init" method)
  //Do whatever you want here...
  //At some point you should create a DOM element you want mounted to the page

  return {
    element: element,//this is the elment you want mounted the page

    update: //same API as virtual-dom widget's "update" method

    destroy: //same API as virtual-dom widget's "destroy" method
  };
});

...
  //somwhere in your render
  MyWidgetThing(props),
...

License

MIT

About

virtual-dom widget constructor that persists it's local state between renders

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published