1.0.1 • Published 11 years ago

dom-widget v1.0.1

Weekly downloads
1
License
-
Repository
github
Last release
11 years ago

dom-widget

browser support

Sugar to create a widget

Example

A widget in this case is a combination of a HTML string and an JavaScript implementation.

Widget returns a function which when called will create a new elements hash from unpack-html using the given HTML template and pass it to you.

The value you return will be passed through but if it doesn't have a view property then a view property will be set to be elements.root

var events = require("dom-reduce/event")
var fold = require("reducers/fold")
var document = require("global-scope/document")
var console = require("console")

var Widget = require("dom-widget")

var html = "<div><input data-marker='foo' /></div>"

var widget = Widget(html, function (elements, data) {
    console.log("args", arguments)
    elements.foo.value = data

    return events(elements.foo, "keypress")
})

var item = widget("hello world")
document.body.appendChild(item.view)

fold(item, function (event) {
    console.log("keypress events", event)
    // keypress events
})

Installation

npm install dom-widget

Contributors

  • Raynos

MIT Licenced