https://github.com/smallhelm/virtual-dom-closure-widget
virtual-dom widget constructor that persists it's local state between renders
https://github.com/smallhelm/virtual-dom-closure-widget
Last synced: about 1 year ago
JSON representation
virtual-dom widget constructor that persists it's local state between renders
- Host: GitHub
- URL: https://github.com/smallhelm/virtual-dom-closure-widget
- Owner: smallhelm
- License: mit
- Created: 2015-11-27T21:12:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-27T22:50:40.000Z (over 10 years ago)
- Last Synced: 2025-02-04T22:28:15.669Z (over 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```sh
$ npm i && npm start
```
It will give you localhost url to open in your browser and see it running.
## API
```js
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