Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add a simple widget

  • Loading branch information...
commit 88979e768ee2849f5c98de56f1990d9784a50424 1 parent cc74421
Dominic Tarr authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 widget.js
13 widget.js
View
@@ -2,7 +2,14 @@
module.exports = function (rarry, template) {
var root = document.createElement('div')
- template = template || require('./default-template')
+ template = template || function (val, key, el) {
+ function pre (val) { return '<pre>'+JSON.stringify(val)+'</pre>' }
+ if(el)
+ return el.innerHTML = pre(val), el
+ var el = document.createElement('span')
+ el.innerHTML = pre(val)
+ return el
+ }
console.log(template)
@@ -16,6 +23,10 @@ module.exports = function (rarry, template) {
function update (key, change) {
var el
if(el = elements[key]) {
+ if(change == null) {
+ return root.removeChild(el)
+ }
+
var _el = template.call(el, change, key, el)
if(_el != el) {
elements[key] = _el
Please sign in to comment.
Something went wrong with that request. Please try again.