Skip to content

Instantly share code, notes, and snippets.

@troch
Created November 28, 2015 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troch/752d87b73f7d607ccbf9 to your computer and use it in GitHub Desktop.
Save troch/752d87b73f7d607ccbf9 to your computer and use it in GitHub Desktop.
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var element = require('virtual-element');
var deku = require('deku');
var timer = require('deku-timer').default;
function render(component) {
var props = component.props;
return element('div', {}, 'Started ' + props.tick * props.delay + 'ms ago.');
}
function countdown(component) {
var props = component.props;
if (props.from - props.tick === 0) props.stop();
return element('div', {}, props.from - props.tick);
}
var Component = { render: render };
var Timer1 = timer(1000)(Component);
var Timer2 = timer(2000)(Component);
var Countdown = { render: countdown };
var Countdown1 = timer(1000)(Countdown);
var app = deku.tree(element('div', {}, [
element(Timer1),
element(Timer2),
element(Countdown1, { from: 20 })
]));
deku.render(app, document.body);
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var base64=require("base64-js");var ieee754=require("ieee754");var isArray=require("is-array");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;Buffer.poolSize=8192;var kMaxLength=1073741823;var rootParent={};Buffer.TYPED_ARRAY_SUPPORT=function(){try{var buf=new ArrayBuffer(0);var arr=new Uint8Array(buf);arr.foo=function(){return 42};return 42===arr.foo()&&typeof arr.subarray==="function"&&new Uint8Array(1).subarray(1,1).byteLength===0}catch(e){return false}}();function Buffer(subject,encoding,noZero){if(!(this instanceof Buffer))return new Buffer(subject,encoding,noZero);var type=typeof subject;var length;if(type==="number")length=subject>0?subject>>>0:0;else if(type==="string"){length=Buffer.byteLength(subject,encoding)}else if(type==="object"&&subject!==null){if(subject.type==="Buffer"&&isArray(subject.data))subject=subject.data;length=+subject.length>0?Math.floor(+subject.length):0}else throw new TypeError("must start with number, buffer, array or string");if(length>kMaxLength)throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+kMaxLength.toString(16)+" bytes");var buf;if(Buffer.TYPED_ARRAY_SUPPORT){buf=Buffer._augment(new Uint8Array(length))}else{buf=this;buf.length=length;buf._isBuffer=true}var i;if(Buffer.TYPED_ARRAY_SUPPORT&&typeof subject.byteLength==="number"){buf._set(subject)}else if(isArrayish(subject)){if(Buffer.isBuffer(subject)){for(i=0;i<length;i++)buf[i]=subject.readUInt8(i)}else{for(i=0;i<length;i++)buf[i]=(subject[i]%256+256)%256}}else if(type==="string"){buf.write(subject,0,encoding)}else if(type==="number"&&!Buffer.TYPED_ARRAY_SUPPORT&&!noZero){for(i=0;i<length;i++){buf[i]=0}}if(length>0&&length<=Buffer.poolSize)buf.parent=rootParent;return buf}function SlowBuffer(subject,encoding,noZero){if(!(this instanceof SlowBuffer))return new SlowBuffer(subject,encoding,noZero);var buf=new Buffer(subject,encoding,noZero);delete buf.parent;return buf}Buffer.isBuffer=function(b){return!!(b!=null&&b._isBuffer)};Buffer.compare=function(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b))throw new TypeError("Arguments must be Buffers");var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i<len&&a[i]===b[i];i++){}if(i!==len){x=a[i];y=b[i]}if(x<y)return-1;if(y<x)return 1;return 0};Buffer.isEncoding=function(encoding){switch(String(encoding).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return true;default:return false}};Buffer.concat=function(list,totalLength){if(!isArray(list))throw new TypeError("Usage: Buffer.concat(list[, length])");if(list.length===0){return new Buffer(0)}else if(list.length===1){return list[0]}var i;if(totalLength===undefined){totalLength=0;for(i=0;i<list.length;i++){totalLength+=list[i].length}}var buf=new Buffer(totalLength);var pos=0;for(i=0;i<list.length;i++){var item=list[i];item.copy(buf,pos);pos+=item.length}return buf};Buffer.byteLength=function(str,encoding){var ret;str=str+"";switch(encoding||"utf8"){case"ascii":case"binary":case"raw":ret=str.length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=str.length*2;break;case"hex":ret=str.length>>>1;break;case"utf8":case"utf-8":ret=utf8ToBytes(str).length;break;case"base64":ret=base64ToBytes(str).length;break;default:ret=str.length}return ret};Buffer.prototype.length=undefined;Buffer.prototype.parent=undefined;Buffer.prototype.toString=function(encoding,start,end){var loweredCase=false;start=start>>>0;end=end===undefined||end===Infinity?this.length:end>>>0;if(!encoding)encoding="utf8";if(start<0)start=0;if(end>this.length)end=this.length;if(end<=start)return"";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"binary":return binarySlice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}};Buffer.prototype.equals=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return Buffer.compare(this,b)===0};Buffer.prototype.inspect=function(){var str="";var max=exports.INSPECT_MAX_BYTES;if(this.length>0){str=this.toString("hex",0,max).match(/.{2}/g).join(" ");if(this.length>max)str+=" ... "}return"<Buffer "+str+">"};Buffer.prototype.compare=function(b){if(!Buffer.isBuffer(b))throw new TypeError("Argument must be a Buffer");return Buffer.compare(this,b)};Buffer.prototype.get=function(offset){console.log(".get() is deprecated. Access using array indexes instead.");return this.readUInt8(offset)};Buffer.prototype.set=function(v,offset){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(v,offset)};function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;if(!length){length=remaining}else{length=Number(length);if(length>remaining){length=remaining}}var strLen=string.length;if(strLen%2!==0)throw new Error("Invalid hex string");if(length>strLen/2){length=strLen/2}for(var i=0;i<length;i++){var byte=parseInt(string.substr(i*2,2),16);if(isNaN(byte))throw new Error("Invalid hex string");buf[offset+i]=byte}return i}function utf8Write(buf,string,offset,length){var charsWritten=blitBuffer(utf8ToBytes(string,buf.length-offset),buf,offset,length);return charsWritten}function asciiWrite(buf,string,offset,length){var charsWritten=blitBuffer(asciiToBytes(string),buf,offset,length);return charsWritten}function binaryWrite(buf,string,offset,length){return asciiWrite(buf,string,offset,length)}function base64Write(buf,string,offset,length){var charsWritten=blitBuffer(base64ToBytes(string),buf,offset,length);return charsWritten}function utf16leWrite(buf,string,offset,length){var charsWritten=blitBuffer(utf16leToBytes(string,buf.length-offset),buf,offset,length,2);return charsWritten}Buffer.prototype.write=function(string,offset,length,encoding){if(isFinite(offset)){if(!isFinite(length)){encoding=length;length=undefined}}else{var swap=encoding;encoding=offset;offset=length;length=swap}offset=Number(offset)||0;if(length<0||offset<0||offset>this.length)throw new RangeError("attempt to write outside buffer bounds");var remaining=this.length-offset;if(!length){length=remaining}else{length=Number(length);if(length>remaining){length=remaining}}encoding=String(encoding||"utf8").toLowerCase();var ret;switch(encoding){case"hex":ret=hexWrite(this,string,offset,length);break;case"utf8":case"utf-8":ret=utf8Write(this,string,offset,length);break;case"ascii":ret=asciiWrite(this,string,offset,length);break;case"binary":ret=binaryWrite(this,string,offset,length);break;case"base64":ret=base64Write(this,string,offset,length);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":ret=utf16leWrite(this,string,offset,length);break;default:throw new TypeError("Unknown encoding: "+encoding)}return ret};Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){var res="";var tmp="";end=Math.min(buf.length,end);for(var i=start;i<end;i++){if(buf[i]<=127){res+=decodeUtf8Char(tmp)+String.fromCharCode(buf[i]);tmp=""}else{tmp+="%"+buf[i].toString(16)}}return res+decodeUtf8Char(tmp)}function asciiSlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;i<end;i++){ret+=String.fromCharCode(buf[i]&127)}return ret}function binarySlice(buf,start,end){var ret="";end=Math.min(buf.length,end);for(var i=start;i<end;i++){ret+=String.fromCharCode(buf[i])}return ret}function hexSlice(buf,start,end){var len=buf.length;if(!start||start<0)start=0;if(!end||end<0||end>len)end=len;var out="";for(var i=start;i<end;i++){out+=toHex(buf[i])}return out}function utf16leSlice(buf,start,end){var bytes=buf.slice(start,end);var res="";for(var i=0;i<bytes.length;i+=2){res+=String.fromCharCode(bytes[i]+bytes[i+1]*256)}return res}Buffer.prototype.slice=function(start,end){var len=this.length;start=~~start;end=end===undefined?len:~~end;if(start<0){start+=len;if(start<0)start=0}else if(start>len){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(end<start)end=start;var newBuf;if(Buffer.TYPED_ARRAY_SUPPORT){newBuf=Buffer._augment(this.subarray(start,end))}else{var sliceLen=end-start;newBuf=new Buffer(sliceLen,undefined,true);for(var i=0;i<sliceLen;i++){newBuf[i]=this[i+start]}}if(newBuf.length)newBuf.parent=this.parent||this;return newBuf};function checkOffset(offset,ext,length){if(offset%1!==0||offset<0)throw new RangeError("offset is not uint");if(offset+ext>length)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i<byteLength&&(mul*=256))val+=this[offset+i]*mul;return val};Buffer.prototype.readUIntBE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256))val+=this[offset+--byteLength]*mul;return val};Buffer.prototype.readUInt8=function(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i<byteLength&&(mul*=256))val+=this[offset+i]*mul;mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256))val+=this[offset+--i]*mul;mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError("buffer must be a Buffer instance");if(value>max||value<min)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range")}Buffer.prototype.writeUIntLE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var mul=1;var i=0;this[offset]=value&255;while(++i<byteLength&&(mul*=256))this[offset+i]=value/mul>>>0&255;return offset+byteLength};Buffer.prototype.writeUIntBE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength),0);var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256))this[offset+i]=value/mul>>>0&255;return offset+byteLength};Buffer.prototype.writeUInt8=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);this[offset]=value;return offset+1};function objectWriteUInt16(buf,value,offset,littleEndian){if(value<0)value=65535+value+1;for(var i=0,j=Math.min(buf.length-offset,2);i<j;i++){buf[offset+i]=(value&255<<8*(littleEndian?i:1-i))>>>(littleEndian?i:1-i)*8}}Buffer.prototype.writeUInt16LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8}else objectWriteUInt16(this,value,offset,true);return offset+2};Buffer.prototype.writeUInt16BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value}else objectWriteUInt16(this,value,offset,false);return offset+2};function objectWriteUInt32(buf,value,offset,littleEndian){if(value<0)value=4294967295+value+1;for(var i=0,j=Math.min(buf.length-offset,4);i<j;i++){buf[offset+i]=value>>>(littleEndian?i:3-i)*8&255}}Buffer.prototype.writeUInt32LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value}else objectWriteUInt32(this,value,offset,true);return offset+4};Buffer.prototype.writeUInt32BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value}else objectWriteUInt32(this,value,offset,false);return offset+4};Buffer.prototype.writeIntLE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1))}var i=0;var mul=1;var sub=value<0?1:0;this[offset]=value&255;while(++i<byteLength&&(mul*=256))this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength};Buffer.prototype.writeIntBE=function(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkInt(this,value,offset,byteLength,Math.pow(2,8*byteLength-1)-1,-Math.pow(2,8*byteLength-1))}var i=byteLength-1;var mul=1;var sub=value<0?1:0;this[offset+i]=value&255;while(--i>=0&&(mul*=256))this[offset+i]=(value/mul>>0)-sub&255;return offset+byteLength};Buffer.prototype.writeInt8=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);if(value<0)value=255+value+1;this[offset]=value;return offset+1};Buffer.prototype.writeInt16LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8}else objectWriteUInt16(this,value,offset,true);return offset+2};Buffer.prototype.writeInt16BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value}else objectWriteUInt16(this,value,offset,false);return offset+2};Buffer.prototype.writeInt32LE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24}else objectWriteUInt32(this,value,offset,true);return offset+4};Buffer.prototype.writeInt32BE=function(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value}else objectWriteUInt32(this,value,offset,false);return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(value>max||value<min)throw new RangeError("value is out of bounds");if(offset+ext>buf.length)throw new RangeError("index out of range");if(offset<0)throw new RangeError("index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){if(!noAssert)checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38);ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){if(!noAssert)checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308);ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function(target,target_start,start,end){var source=this;if(!start)start=0;if(!end&&end!==0)end=this.length;if(target_start>=target.length)target_start=target.length;if(!target_start)target_start=0;if(end>0&&end<start)end=start;if(end===start)return 0;if(target.length===0||source.length===0)return 0;if(target_start<0)throw new RangeError("targetStart out of bounds");if(start<0||start>=source.length)throw new RangeError("sourceStart out of bounds");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-target_start<end-start)end=target.length-target_start+start;var len=end-start;if(len<1e3||!Buffer.TYPED_ARRAY_SUPPORT){for(var i=0;i<len;i++){target[i+target_start]=this[i+start]}}else{target._set(this.subarray(start,start+len),target_start)}return len};Buffer.prototype.fill=function(value,start,end){if(!value)value=0;if(!start)start=0;if(!end)end=this.length;if(end<start)throw new RangeError("end < start");if(end===start)return;if(this.length===0)return;if(start<0||start>=this.length)throw new RangeError("start out of bounds");if(end<0||end>this.length)throw new RangeError("end out of bounds");var i;if(typeof value==="number"){for(i=start;i<end;i++){this[i]=value}}else{var bytes=utf8ToBytes(value.toString());var len=bytes.length;for(i=start;i<end;i++){this[i]=bytes[i%len]}}return this};Buffer.prototype.toArrayBuffer=function(){if(typeof Uint8Array!=="undefined"){if(Buffer.TYPED_ARRAY_SUPPORT){return new Buffer(this).buffer}else{var buf=new Uint8Array(this.length);for(var i=0,len=buf.length;i<len;i+=1){buf[i]=this[i]}return buf.buffer}}else{throw new TypeError("Buffer.toArrayBuffer not supported in this browser")}};var BP=Buffer.prototype;Buffer._augment=function(arr){arr.constructor=Buffer;arr._isBuffer=true;arr._get=arr.get;arr._set=arr.set;arr.get=BP.get;arr.set=BP.set;arr.write=BP.write;arr.toString=BP.toString;arr.toLocaleString=BP.toString;arr.toJSON=BP.toJSON;arr.equals=BP.equals;arr.compare=BP.compare;arr.copy=BP.copy;arr.slice=BP.slice;arr.readUIntLE=BP.readUIntLE;arr.readUIntBE=BP.readUIntBE;arr.readUInt8=BP.readUInt8;arr.readUInt16LE=BP.readUInt16LE;arr.readUInt16BE=BP.readUInt16BE;arr.readUInt32LE=BP.readUInt32LE;arr.readUInt32BE=BP.readUInt32BE;arr.readIntLE=BP.readIntLE;arr.readIntBE=BP.readIntBE;arr.readInt8=BP.readInt8;arr.readInt16LE=BP.readInt16LE;arr.readInt16BE=BP.readInt16BE;arr.readInt32LE=BP.readInt32LE;arr.readInt32BE=BP.readInt32BE;arr.readFloatLE=BP.readFloatLE;arr.readFloatBE=BP.readFloatBE;arr.readDoubleLE=BP.readDoubleLE;arr.readDoubleBE=BP.readDoubleBE;arr.writeUInt8=BP.writeUInt8;arr.writeUIntLE=BP.writeUIntLE;arr.writeUIntBE=BP.writeUIntBE;arr.writeUInt16LE=BP.writeUInt16LE;arr.writeUInt16BE=BP.writeUInt16BE;arr.writeUInt32LE=BP.writeUInt32LE;arr.writeUInt32BE=BP.writeUInt32BE;arr.writeIntLE=BP.writeIntLE;arr.writeIntBE=BP.writeIntBE;arr.writeInt8=BP.writeInt8;arr.writeInt16LE=BP.writeInt16LE;arr.writeInt16BE=BP.writeInt16BE;arr.writeInt32LE=BP.writeInt32LE;arr.writeInt32BE=BP.writeInt32BE;arr.writeFloatLE=BP.writeFloatLE;arr.writeFloatBE=BP.writeFloatBE;arr.writeDoubleLE=BP.writeDoubleLE;arr.writeDoubleBE=BP.writeDoubleBE;arr.fill=BP.fill;arr.inspect=BP.inspect;arr.toArrayBuffer=BP.toArrayBuffer;return arr};var INVALID_BASE64_RE=/[^+\/0-9A-z\-]/g;function base64clean(str){str=stringtrim(str).replace(INVALID_BASE64_RE,"");if(str.length<2)return"";while(str.length%4!==0){str=str+"="}return str}function stringtrim(str){if(str.trim)return str.trim();return str.replace(/^\s+|\s+$/g,"")}function isArrayish(subject){return isArray(subject)||Buffer.isBuffer(subject)||subject&&typeof subject==="object"&&typeof subject.length==="number"}function toHex(n){if(n<16)return"0"+n.toString(16);return n.toString(16)}function utf8ToBytes(string,units){var codePoint,length=string.length;var leadSurrogate=null;units=units||Infinity;var bytes=[];var i=0;for(;i<length;i++){codePoint=string.charCodeAt(i);if(codePoint>55295&&codePoint<57344){if(leadSurrogate){if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}else{codePoint=leadSurrogate-55296<<10|codePoint-56320|65536;leadSurrogate=null}}else{if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}else{leadSurrogate=codePoint;continue}}}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=null}if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<2097152){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i<str.length;i++){byteArray.push(str.charCodeAt(i)&255)}return byteArray}function utf16leToBytes(str,units){var c,hi,lo;var byteArray=[];for(var i=0;i<str.length;i++){if((units-=2)<0)break;c=str.charCodeAt(i);hi=c>>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length,unitSize){if(unitSize)length-=length%unitSize;for(var i=0;i<length;i++){if(i+offset>=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function decodeUtf8Char(str){try{return decodeURIComponent(str)}catch(err){return String.fromCharCode(65533)}}},{"base64-js":2,ieee754:3,"is-array":4}],2:[function(require,module,exports){var lookup="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";(function(exports){"use strict";var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;var PLUS="+".charCodeAt(0);var SLASH="/".charCodeAt(0);var NUMBER="0".charCodeAt(0);var LOWER="a".charCodeAt(0);var UPPER="A".charCodeAt(0);var PLUS_URL_SAFE="-".charCodeAt(0);var SLASH_URL_SAFE="_".charCodeAt(0);function decode(elt){var code=elt.charCodeAt(0);if(code===PLUS||code===PLUS_URL_SAFE)return 62;if(code===SLASH||code===SLASH_URL_SAFE)return 63;if(code<NUMBER)return-1;if(code<NUMBER+10)return code-NUMBER+26+26;if(code<UPPER+26)return code-UPPER;if(code<LOWER+26)return code-LOWER+26}function b64ToByteArray(b64){var i,j,l,tmp,placeHolders,arr;if(b64.length%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var len=b64.length;placeHolders="="===b64.charAt(len-2)?2:"="===b64.charAt(len-1)?1:0;arr=new Arr(b64.length*3/4-placeHolders);l=placeHolders>0?b64.length-4:b64.length;var L=0;function push(v){arr[L++]=v}for(i=0,j=0;i<l;i+=4,j+=3){tmp=decode(b64.charAt(i))<<18|decode(b64.charAt(i+1))<<12|decode(b64.charAt(i+2))<<6|decode(b64.charAt(i+3));push((tmp&16711680)>>16);push((tmp&65280)>>8);push(tmp&255)}if(placeHolders===2){tmp=decode(b64.charAt(i))<<2|decode(b64.charAt(i+1))>>4;push(tmp&255)}else if(placeHolders===1){tmp=decode(b64.charAt(i))<<10|decode(b64.charAt(i+1))<<4|decode(b64.charAt(i+2))>>2;push(tmp>>8&255);push(tmp&255)}return arr}function uint8ToBase64(uint8){var i,extraBytes=uint8.length%3,output="",temp,length;function encode(num){return lookup.charAt(num)}function tripletToBase64(num){return encode(num>>18&63)+encode(num>>12&63)+encode(num>>6&63)+encode(num&63)}for(i=0,length=uint8.length-extraBytes;i<length;i+=3){temp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2];output+=tripletToBase64(temp)}switch(extraBytes){case 1:temp=uint8[uint8.length-1];output+=encode(temp>>2);output+=encode(temp<<4&63);output+="==";break;case 2:temp=(uint8[uint8.length-2]<<8)+uint8[uint8.length-1];output+=encode(temp>>10);output+=encode(temp>>4&63);output+=encode(temp<<2&63);output+="=";break}return output}exports.toByteArray=b64ToByteArray;exports.fromByteArray=uint8ToBase64})(typeof exports==="undefined"?this.base64js={}:exports)},{}],3:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m,eLen=nBytes*8-mLen-1,eMax=(1<<eLen)-1,eBias=eMax>>1,nBits=-7,i=isLE?nBytes-1:0,d=isLE?-1:1,s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8);m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8);if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c,eLen=nBytes*8-mLen-1,eMax=(1<<eLen)-1,eBias=eMax>>1,rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0,i=isLE?0:nBytes-1,d=isLE?1:-1,s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8);e=e<<mLen|m;eLen+=mLen;for(;eLen>0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8);buffer[offset+i-d]|=s*128}},{}],4:[function(require,module,exports){var isArray=Array.isArray;var str=Object.prototype.toString;module.exports=isArray||function(val){return!!val&&"[object Array]"==str.call(val)}},{}],5:[function(require,module,exports){var Emitter=require("component-emitter");module.exports=Application;function Application(element){if(!(this instanceof Application))return new Application(element);this.options={};this.sources={};this.element=element}Emitter(Application.prototype);Application.prototype.use=function(plugin){plugin(this);return this};Application.prototype.option=function(name,val){this.options[name]=val;return this};Application.prototype.set=function(name,data){this.sources[name]=data;this.emit("source",name,data);return this};Application.prototype.mount=function(element){this.element=element;this.emit("mount",element);return this};Application.prototype.unmount=function(){if(!this.element)return;this.element=null;this.emit("unmount");return this}},{"component-emitter":11}],6:[function(require,module,exports){module.exports={onBlur:"blur",onChange:"change",onClick:"click",onContextMenu:"contextmenu",onCopy:"copy",onCut:"cut",onDoubleClick:"dblclick",onDrag:"drag",onDragEnd:"dragend",onDragEnter:"dragenter",onDragExit:"dragexit",onDragLeave:"dragleave",onDragOver:"dragover",onDragStart:"dragstart",onDrop:"drop",onError:"error",onFocus:"focus",onInput:"input",onInvalid:"invalid",onKeyDown:"keydown",onKeyPress:"keypress",onKeyUp:"keyup",onMouseDown:"mousedown",onMouseEnter:"mouseenter",onMouseLeave:"mouseleave",onMouseMove:"mousemove",onMouseOut:"mouseout",onMouseOver:"mouseover",onMouseUp:"mouseup",onPaste:"paste",onReset:"reset",onScroll:"scroll",onSubmit:"submit",onTouchCancel:"touchcancel",onTouchEnd:"touchend",onTouchMove:"touchmove",onTouchStart:"touchstart",onWheel:"wheel"}},{}],7:[function(require,module,exports){var type=require("component-type");module.exports=function nodeType(node){var v=type(node);if(v==="null"||node===false)return"empty";if(v!=="object")return"text";if(type(node.type)==="string")return"element";return"component"}},{"component-type":13}],8:[function(require,module,exports){var raf=require("component-raf");var isDom=require("is-dom");var uid=require("get-uid");var keypath=require("object-path");var events=require("./events");var svg=require("./svg");var defaults=require("object-defaults");var forEach=require("fast.js/forEach");var assign=require("fast.js/object/assign");var reduce=require("fast.js/reduce");var nodeType=require("./node-type");module.exports=render;function render(app,container,opts){var frameId;var isRendering;var rootId="root";var currentElement;var currentNativeElement;var connections={};var components={};var entities={};var handlers={};var mountQueue=[];var children={};children[rootId]={};if(!isDom(container)){throw new Error("Container element must be a DOM element")}var options=defaults(assign({},app.options||{},opts||{}),{batching:true});var rootElement=getRootElement(container);addNativeEventListeners();app.on("unmount",onunmount);app.on("mount",onmount);app.on("source",onupdate);if(app.element)render();function teardown(){removeNativeEventListeners();removeNativeElement();app.off("unmount",onunmount);app.off("mount",onmount);app.off("source",onupdate)}function onmount(){invalidate()}function onunmount(){removeNativeElement();currentElement=null}function onupdate(name,data){if(!connections[name])return;connections[name].forEach(function(update){
update(data)})}function mountEntity(entity){register(entity);setSources(entity);children[entity.id]={};entities[entity.id]=entity;commit(entity);trigger("beforeMount",entity,[entity.context]);trigger("beforeRender",entity,[entity.context]);var virtualElement=renderEntity(entity);var nativeElement=toNative(entity.id,"0",virtualElement);entity.virtualElement=virtualElement;entity.nativeElement=nativeElement;mountQueue.push(entity.id);return nativeElement}function unmountEntity(entityId){var entity=entities[entityId];if(!entity)return;trigger("beforeUnmount",entity,[entity.context,entity.nativeElement]);unmountChildren(entityId);removeAllEvents(entityId);var componentEntities=components[entityId].entities;delete componentEntities[entityId];delete components[entityId];delete entities[entityId];delete children[entityId]}function renderEntity(entity){var component=entity.component;var fn=typeof component==="function"?component:component.render;if(!fn)throw new Error("Component needs a render function");var result=fn(entity.context,setState(entity));if(!result)throw new Error("Render function must return an element.");return result}function setState(entity){return function(nextState){updateEntityState(entity,nextState)}}function invalidate(){if(!options.batching){if(!isRendering)render()}else{if(!frameId)frameId=raf(render)}}function render(){clearFrame();if(isRendering){frameId=raf(render);return}else{isRendering=true}if(!currentNativeElement){currentElement=app.element;currentNativeElement=toNative(rootId,"0",currentElement);if(container.children.length>0){console.info("deku: The container element is not empty. These elements will be removed. Read more: http://cl.ly/b0Sr")}if(container===document.body){console.warn("deku: Using document.body is allowed but it can cause some issues. Read more: http://cl.ly/b0SC")}removeAllChildren(container);container.appendChild(currentNativeElement)}else if(currentElement!==app.element){currentNativeElement=patch(rootId,currentElement,app.element,currentNativeElement);currentElement=app.element;updateChildren(rootId)}else{updateChildren(rootId)}flushMountQueue();isRendering=false}function flushMountQueue(){while(mountQueue.length>0){var entityId=mountQueue.shift();var entity=entities[entityId];trigger("afterRender",entity,[entity.context,entity.nativeElement]);trigger("afterMount",entity,[entity.context,entity.nativeElement,setState(entity)])}}function clearFrame(){if(!frameId)return;raf.cancel(frameId);frameId=0}function updateEntity(entityId){var entity=entities[entityId];setSources(entity);if(!shouldUpdate(entity)){commit(entity);return updateChildren(entityId)}var currentTree=entity.virtualElement;var nextProps=entity.pendingProps;var nextState=entity.pendingState;var previousState=entity.context.state;var previousProps=entity.context.props;trigger("beforeUpdate",entity,[entity.context,nextProps,nextState]);trigger("beforeRender",entity,[entity.context]);commit(entity);var nextTree=renderEntity(entity);if(nextTree===currentTree)return updateChildren(entityId);entity.nativeElement=patch(entityId,currentTree,nextTree,entity.nativeElement);entity.virtualElement=nextTree;updateChildren(entityId);trigger("afterRender",entity,[entity.context,entity.nativeElement]);trigger("afterUpdate",entity,[entity.context,previousProps,previousState,setState(entity)])}function updateChildren(entityId){forEach(children[entityId],function(childId){updateEntity(childId)})}function unmountChildren(entityId){forEach(children[entityId],function(childId){unmountEntity(childId)})}function removeNativeElement(){clearFrame();removeElement(rootId,"0",currentNativeElement);currentNativeElement=null}function toNative(entityId,path,vnode){switch(nodeType(vnode)){case"text":return toNativeText(vnode);case"empty":return toNativeEmptyElement(entityId,path);case"element":return toNativeElement(entityId,path,vnode);case"component":return toNativeComponent(entityId,path,vnode)}}function toNativeText(text){return document.createTextNode(text)}function toNativeElement(entityId,path,vnode){var el;var attributes=vnode.attributes;var tagName=vnode.type;var childNodes=vnode.children;if(svg.isElement(tagName)){el=document.createElementNS(svg.namespace,tagName)}else{el=document.createElement(tagName)}forEach(attributes,function(value,name){setAttribute(entityId,path,el,name,value)});forEach(childNodes,function(child,i){var childEl=toNative(entityId,path+"."+i,child);if(!childEl.parentNode)el.appendChild(childEl)});el.__entity__=entityId;el.__path__=path;return el}function toNativeEmptyElement(entityId,path){var el=document.createElement("noscript");el.__entity__=entityId;el.__path__=path;return el}function toNativeComponent(entityId,path,vnode){var child=new Entity(vnode.type,assign({children:vnode.children},vnode.attributes),entityId);children[entityId][path]=child.id;return mountEntity(child)}function patch(entityId,prev,next,el){return diffNode("0",entityId,prev,next,el)}function diffNode(path,entityId,prev,next,el){var leftType=nodeType(prev);var rightType=nodeType(next);if(leftType!==rightType)return replaceElement(entityId,path,el,next);switch(rightType){case"text":return diffText(prev,next,el);case"empty":return el;case"element":return diffElement(path,entityId,prev,next,el);case"component":return diffComponent(path,entityId,prev,next,el)}}function diffText(previous,current,el){if(current!==previous)el.data=current;return el}function diffChildren(path,entityId,prev,next,el){var positions=[];var hasKeys=false;var childNodes=Array.prototype.slice.apply(el.childNodes);var leftKeys=reduce(prev.children,keyMapReducer,{});var rightKeys=reduce(next.children,keyMapReducer,{});var currentChildren=assign({},children[entityId]);function keyMapReducer(acc,child,i){if(child&&child.attributes&&child.attributes.key!=null){acc[child.attributes.key]={element:child,index:i};hasKeys=true}return acc}if(hasKeys){forEach(leftKeys,function(leftNode,key){if(rightKeys[key]==null){var leftPath=path+"."+leftNode.index;removeElement(entityId,leftPath,childNodes[leftNode.index])}});forEach(rightKeys,function(rightNode,key){var leftNode=leftKeys[key];if(leftNode==null)return;var leftPath=path+"."+leftNode.index;positions[rightNode.index]=diffNode(leftPath,entityId,leftNode.element,rightNode.element,childNodes[leftNode.index])});forEach(rightKeys,function(rightNode,key){var leftNode=leftKeys[key];if(leftNode==null||leftNode.index===rightNode.index)return;var rightPath=path+"."+rightNode.index;var leftPath=path+"."+leftNode.index;forEach(currentChildren,function(childId,childPath){if(leftPath===childPath){delete children[entityId][childPath];children[entityId][rightPath]=childId}})});forEach(rightKeys,function(rightNode,key){var rightPath=path+"."+rightNode.index;if(leftKeys[key]==null){positions[rightNode.index]=toNative(entityId,rightPath,rightNode.element)}})}else{var maxLength=Math.max(prev.children.length,next.children.length);for(var i=0;i<maxLength;i++){var leftNode=prev.children[i];var rightNode=next.children[i];if(rightNode===undefined){removeElement(entityId,path+"."+i,childNodes[i]);continue}if(leftNode===undefined){positions[i]=toNative(entityId,path+"."+i,rightNode);continue}positions[i]=diffNode(path+"."+i,entityId,leftNode,rightNode,childNodes[i])}}forEach(positions,function(childEl,newPosition){var target=el.childNodes[newPosition];if(childEl&&childEl!==target){if(target){el.insertBefore(childEl,target)}else{el.appendChild(childEl)}}})}function diffAttributes(prev,next,el,entityId,path){var nextAttrs=next.attributes;var prevAttrs=prev.attributes;forEach(nextAttrs,function(value,name){if(events[name]||!(name in prevAttrs)||prevAttrs[name]!==value){setAttribute(entityId,path,el,name,value)}});forEach(prevAttrs,function(value,name){if(!(name in nextAttrs)){removeAttribute(entityId,path,el,name)}})}function diffComponent(path,entityId,prev,next,el){if(next.type!==prev.type){return replaceElement(entityId,path,el,next)}else{var targetId=children[entityId][path];if(targetId){updateEntityProps(targetId,assign({children:next.children},next.attributes))}return el}}function diffElement(path,entityId,prev,next,el){if(next.type!==prev.type)return replaceElement(entityId,path,el,next);diffAttributes(prev,next,el,entityId,path);diffChildren(path,entityId,prev,next,el);return el}function removeElement(entityId,path,el){var childrenByPath=children[entityId];var childId=childrenByPath[path];var entityHandlers=handlers[entityId]||{};var removals=[];if(childId){var child=entities[childId];el=child.nativeElement;unmountEntity(childId);removals.push(path)}else{if(!isElement(el))return el&&el.parentNode.removeChild(el);forEach(childrenByPath,function(childId,childPath){if(childPath===path||isWithinPath(path,childPath)){unmountEntity(childId);removals.push(childPath)}});forEach(entityHandlers,function(fn,handlerPath){if(handlerPath===path||isWithinPath(path,handlerPath)){removeEvent(entityId,handlerPath)}})}forEach(removals,function(path){delete children[entityId][path]});el.parentNode.removeChild(el)}function replaceElement(entityId,path,el,vnode){var parent=el.parentNode;var index=Array.prototype.indexOf.call(parent.childNodes,el);removeElement(entityId,path,el);var newEl=toNative(entityId,path,vnode);var target=parent.childNodes[index];if(target){parent.insertBefore(newEl,target)}else{parent.appendChild(newEl)}if(entityId!=="root"&&path==="0"){updateNativeElement(entityId,newEl)}return newEl}function updateNativeElement(entityId,newEl){var target=entities[entityId];if(target.ownerId==="root")return;if(children[target.ownerId]["0"]===entityId){entities[target.ownerId].nativeElement=newEl;updateNativeElement(target.ownerId,newEl)}}function setAttribute(entityId,path,el,name,value){if(!value){removeAttribute(entityId,path,el,name);return}if(events[name]){addEvent(entityId,path,events[name],value);return}switch(name){case"checked":case"disabled":case"selected":el[name]=true;break;case"innerHTML":el.innerHTML=value;break;case"value":setElementValue(el,value);break;case svg.isAttribute(name):el.setAttributeNS(svg.namespace,name,value);break;default:el.setAttribute(name,value);break}}function removeAttribute(entityId,path,el,name){if(events[name]){removeEvent(entityId,path,events[name]);return}switch(name){case"checked":case"disabled":case"selected":el[name]=false;break;case"innerHTML":el.innerHTML="";case"value":setElementValue(el,null);break;default:el.removeAttribute(name);break}}function isWithinPath(target,path){return path.indexOf(target+".")===0}function isElement(el){return!!(el&&el.tagName)}function removeAllChildren(el){while(el.firstChild)el.removeChild(el.firstChild)}function trigger(name,entity,args){if(typeof entity.component[name]!=="function")return;return entity.component[name].apply(null,args)}function updateEntityProps(entityId,nextProps){var entity=entities[entityId];entity.pendingProps=defaults({},nextProps,entity.component.defaultProps||{});entity.dirty=true;invalidate()}function updateEntityState(entity,nextState){entity.pendingState=assign(entity.pendingState,nextState);entity.dirty=true;invalidate()}function commit(entity){entity.context={state:entity.pendingState,props:entity.pendingProps,id:entity.id};entity.pendingState=assign({},entity.context.state);entity.pendingProps=assign({},entity.context.props);entity.dirty=false;if(typeof entity.component.validate==="function"){entity.component.validate(entity.context)}}function shouldUpdate(entity){if(!entity.dirty)return false;if(!entity.component.shouldUpdate)return true;var nextProps=entity.pendingProps;var nextState=entity.pendingState;var bool=entity.component.shouldUpdate(entity.context,nextProps,nextState);return bool}function register(entity){registerEntity(entity);var component=entity.component;if(component.registered)return;registerSources(entity);component.registered=true}function registerEntity(entity){var component=entity.component;var entities=component.entities=component.entities||{};entities[entity.id]=entity;components[entity.id]=component}function registerSources(entity){var component=components[entity.id];var sources=component.sources;if(sources)return;var entities=component.entities;var map=component.sourceToPropertyName={};component.sources=sources=[];var propTypes=component.propTypes;for(var name in propTypes){var data=propTypes[name];if(!data)continue;if(!data.source)continue;sources.push(data.source);map[data.source]=name}sources.forEach(function(source){connections[source]=connections[source]||[];connections[source].push(update);function update(data){var prop=map[source];for(var entityId in entities){var entity=entities[entityId];var changes={};changes[prop]=data;updateEntityProps(entityId,assign(entity.pendingProps,changes))}}})}function setSources(entity){var component=entity.component;var map=component.sourceToPropertyName;var sources=component.sources;sources.forEach(function(source){var name=map[source];if(entity.pendingProps[name]!=null)return;entity.pendingProps[name]=app.sources[source]})}function addNativeEventListeners(){forEach(events,function(eventType){rootElement.addEventListener(eventType,handleEvent,true)})}function removeNativeEventListeners(){forEach(events,function(eventType){rootElement.removeEventListener(eventType,handleEvent,true)})}function handleEvent(event){var target=event.target;var eventType=event.type;while(target){var fn=keypath.get(handlers,[target.__entity__,target.__path__,eventType]);if(fn){event.delegateTarget=target;if(fn(event)===false)break}target=target.parentNode}}function addEvent(entityId,path,eventType,fn){keypath.set(handlers,[entityId,path,eventType],function(e){var entity=entities[entityId];if(entity){return fn.call(null,e,entity.context,setState(entity))}else{return fn.call(null,e)}})}function removeEvent(entityId,path,eventType){var args=[entityId];if(path)args.push(path);if(eventType)args.push(eventType);keypath.del(handlers,args)}function removeAllEvents(entityId){keypath.del(handlers,[entityId])}function inspect(){return{entities:entities,handlers:handlers,connections:connections,currentElement:currentElement,options:options,app:app,container:container,children:children}}return{remove:teardown,inspect:inspect}}function Entity(component,props,ownerId){this.id=uid();this.ownerId=ownerId;this.component=component;this.propTypes=component.propTypes||{};this.context={};this.context.id=this.id;this.context.props=defaults(props||{},component.defaultProps||{});this.context.state=this.component.initialState?this.component.initialState(this.context.props):{};this.pendingProps=assign({},this.context.props);this.pendingState=assign({},this.context.state);this.dirty=false;this.virtualElement=null;this.nativeElement=null;this.displayName=component.name||"Component"}function getRootElement(el){while(el.parentElement){if(el.tagName==="BODY"||!el.parentElement){return el}el=el.parentElement}return el}function setElementValue(el,value){if(el===document.activeElement&&canSelectText(el)){var start=el.selectionStart;var end=el.selectionEnd;el.value=value;el.setSelectionRange(start,end)}else{el.value=value}}function canSelectText(el){return el.tagName==="INPUT"&&["text","search","password","tel","url"].indexOf(el.type)>-1}},{"./events":6,"./node-type":7,"./svg":10,"component-raf":12,"fast.js/forEach":16,"fast.js/object/assign":19,"fast.js/reduce":22,"get-uid":23,"is-dom":24,"object-defaults":27,"object-path":28}],9:[function(require,module,exports){var defaults=require("object-defaults");var nodeType=require("./node-type");var type=require("component-type");module.exports=function(app){if(!app.element){throw new Error("No element mounted")}function stringify(component,optProps,children){var propTypes=component.propTypes||{};var props=defaults(optProps||{},component.defaultProps||{});var state=component.initialState?component.initialState(props):{};props.children=children;for(var name in propTypes){var options=propTypes[name];if(options.source){props[name]=app.sources[options.source]}}if(component.beforeMount)component.beforeMount({props:props,state:state});if(component.beforeRender)component.beforeRender({props:props,state:state});var node=component.render({props:props,state:state});return stringifyNode(node,"0")}function stringifyNode(node,path){switch(nodeType(node)){case"empty":return"<noscript />";case"text":return node;case"element":var children=node.children;var attributes=node.attributes;var tagName=node.type;var innerHTML=attributes.innerHTML;var str="<"+tagName+attrs(attributes)+">";if(innerHTML){str+=innerHTML}else{for(var i=0,n=children.length;i<n;i++){str+=stringifyNode(children[i],path+"."+i)}}str+="</"+tagName+">";return str;case"component":return stringify(node.type,node.attributes,node.children)}throw new Error("Invalid type")}return stringifyNode(app.element,"0")};function attrs(attributes){var str="";for(var key in attributes){var value=attributes[key];if(key==="innerHTML")continue;if(isValidAttributeValue(value))str+=attr(key,attributes[key])}return str}function attr(key,val){return" "+key+'="'+val+'"'}function isValidAttributeValue(value){var valueType=type(value);switch(valueType){case"string":case"number":return true;case"boolean":return value;default:return false}}},{"./node-type":7,"component-type":13,"object-defaults":27}],10:[function(require,module,exports){module.exports={isElement:require("is-svg-element").isElement,isAttribute:require("is-svg-attribute"),namespace:"http://www.w3.org/2000/svg"}},{"is-svg-attribute":25,"is-svg-element":26}],11:[function(require,module,exports){module.exports=Emitter;function Emitter(obj){if(obj)return mixin(obj)}function mixin(obj){for(var key in Emitter.prototype){obj[key]=Emitter.prototype[key]}return obj}Emitter.prototype.on=Emitter.prototype.addEventListener=function(event,fn){this._callbacks=this._callbacks||{};(this._callbacks["$"+event]=this._callbacks["$"+event]||[]).push(fn);return this};Emitter.prototype.once=function(event,fn){function on(){this.off(event,on);fn.apply(this,arguments)}on.fn=fn;this.on(event,on);return this};Emitter.prototype.off=Emitter.prototype.removeListener=Emitter.prototype.removeAllListeners=Emitter.prototype.removeEventListener=function(event,fn){this._callbacks=this._callbacks||{};if(0==arguments.length){this._callbacks={};return this}var callbacks=this._callbacks["$"+event];if(!callbacks)return this;if(1==arguments.length){delete this._callbacks["$"+event];return this}var cb;for(var i=0;i<callbacks.length;i++){cb=callbacks[i];if(cb===fn||cb.fn===fn){callbacks.splice(i,1);break}}return this};Emitter.prototype.emit=function(event){this._callbacks=this._callbacks||{};var args=[].slice.call(arguments,1),callbacks=this._callbacks["$"+event];if(callbacks){callbacks=callbacks.slice(0);for(var i=0,len=callbacks.length;i<len;++i){callbacks[i].apply(this,args)}}return this};Emitter.prototype.listeners=function(event){this._callbacks=this._callbacks||{};return this._callbacks["$"+event]||[]};Emitter.prototype.hasListeners=function(event){return!!this.listeners(event).length}},{}],12:[function(require,module,exports){exports=module.exports=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||fallback;var prev=(new Date).getTime();function fallback(fn){var curr=(new Date).getTime();var ms=Math.max(0,16-(curr-prev));var req=setTimeout(fn,ms);prev=curr;return req}var cancel=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.clearTimeout;exports.cancel=function(id){cancel.call(window,id)}},{}],13:[function(require,module,exports){(function(Buffer){var toString=Object.prototype.toString;module.exports=function(val){switch(toString.call(val)){case"[object Date]":return"date";case"[object RegExp]":return"regexp";case"[object Arguments]":return"arguments";case"[object Array]":return"array";case"[object Error]":return"error"}if(val===null)return"null";if(val===undefined)return"undefined";if(val!==val)return"nan";if(val&&val.nodeType===1)return"element";if(typeof Buffer!="undefined"&&Buffer.isBuffer(val))return"buffer";val=val.valueOf?val.valueOf():Object.prototype.valueOf.apply(val);return typeof val}}).call(this,require("buffer").Buffer)},{buffer:1}],14:[function(require,module,exports){"use strict";var bindInternal3=require("../function/bindInternal3");module.exports=function fastForEach(subject,fn,thisContext){var length=subject.length,iterator=thisContext!==undefined?bindInternal3(fn,thisContext):fn,i;for(i=0;i<length;i++){iterator(subject[i],i,subject)}}},{"../function/bindInternal3":17}],15:[function(require,module,exports){"use strict";var bindInternal4=require("../function/bindInternal4");module.exports=function fastReduce(subject,fn,initialValue,thisContext){var length=subject.length,iterator=thisContext!==undefined?bindInternal4(fn,thisContext):fn,i,result;if(initialValue===undefined){i=1;result=subject[0]}else{i=0;result=initialValue}for(;i<length;i++){result=iterator(result,subject[i],i,subject)}return result}},{"../function/bindInternal4":18}],16:[function(require,module,exports){"use strict";var forEachArray=require("./array/forEach"),forEachObject=require("./object/forEach");module.exports=function fastForEach(subject,fn,thisContext){if(subject instanceof Array){return forEachArray(subject,fn,thisContext)}else{return forEachObject(subject,fn,thisContext)}}},{"./array/forEach":14,"./object/forEach":20}],17:[function(require,module,exports){"use strict";module.exports=function bindInternal3(func,thisContext){return function(a,b,c){return func.call(thisContext,a,b,c)}}},{}],18:[function(require,module,exports){"use strict";module.exports=function bindInternal4(func,thisContext){return function(a,b,c,d){return func.call(thisContext,a,b,c,d)}}},{}],19:[function(require,module,exports){"use strict";module.exports=function fastAssign(target){var totalArgs=arguments.length,source,i,totalKeys,keys,key,j;for(i=1;i<totalArgs;i++){source=arguments[i];keys=Object.keys(source);totalKeys=keys.length;for(j=0;j<totalKeys;j++){key=keys[j];target[key]=source[key]}}return target}},{}],20:[function(require,module,exports){"use strict";var bindInternal3=require("../function/bindInternal3");module.exports=function fastForEachObject(subject,fn,thisContext){var keys=Object.keys(subject),length=keys.length,iterator=thisContext!==undefined?bindInternal3(fn,thisContext):fn,key,i;for(i=0;i<length;i++){key=keys[i];iterator(subject[key],key,subject)}}},{"../function/bindInternal3":17}],21:[function(require,module,exports){"use strict";var bindInternal4=require("../function/bindInternal4");module.exports=function fastReduceObject(subject,fn,initialValue,thisContext){var keys=Object.keys(subject),length=keys.length,iterator=thisContext!==undefined?bindInternal4(fn,thisContext):fn,i,key,result;if(initialValue===undefined){i=1;result=subject[keys[0]]}else{i=0;result=initialValue}for(;i<length;i++){key=keys[i];result=iterator(result,subject[key],key,subject)}return result}},{"../function/bindInternal4":18}],22:[function(require,module,exports){"use strict";var reduceArray=require("./array/reduce"),reduceObject=require("./object/reduce");module.exports=function fastReduce(subject,fn,initialValue,thisContext){if(subject instanceof Array){return reduceArray(subject,fn,initialValue,thisContext)}else{return reduceObject(subject,fn,initialValue,thisContext)}}},{"./array/reduce":15,"./object/reduce":21}],23:[function(require,module,exports){var counter=Date.now()%1e9;module.exports=function getUid(){return(Math.random()*1e9>>>0)+counter++}},{}],24:[function(require,module,exports){module.exports=function isNode(val){if(!val||typeof val!=="object")return false;if(window&&"object"==typeof window.Node)return val instanceof window.Node;return"number"==typeof val.nodeType&&"string"==typeof val.nodeName}},{}],25:[function(require,module,exports){exports.attributes={cx:true,cy:true,d:true,dx:true,dy:true,fill:true,fillOpacity:true,fontFamily:true,fontSize:true,fx:true,fy:true,gradientTransform:true,gradientUnits:true,markerEnd:true,markerMid:true,markerStart:true,offset:true,opacity:true,patternContentUnits:true,patternUnits:true,points:true,preserveAspectRatio:true,r:true,rx:true,ry:true,spreadMethod:true,stopColor:true,stopOpacity:true,stroke:true,strokeDasharray:true,strokeLinecap:true,strokeOpacity:true,strokeWidth:true,textAnchor:true,transform:true,version:true,viewBox:true,x1:true,x2:true,x:true,y1:true,y2:true,y:true};module.exports=function(attr){return attr in exports.attributes}},{}],26:[function(require,module,exports){exports.elements={animate:true,circle:true,defs:true,ellipse:true,g:true,line:true,linearGradient:true,mask:true,path:true,pattern:true,polygon:true,polyline:true,radialGradient:true,rect:true,stop:true,svg:true,text:true,tspan:true};exports.isElement=function(name){return name in exports.elements}},{}],27:[function(require,module,exports){"use strict";module.exports=function(target){target=target||{};for(var i=1;i<arguments.length;i++){var source=arguments[i];if(!source)continue;Object.getOwnPropertyNames(source).forEach(function(key){if(undefined===target[key])target[key]=source[key]})}return target}},{}],28:[function(require,module,exports){(function(root,factory){"use strict";if(typeof module==="object"&&typeof module.exports==="object"){module.exports=factory()}else if(typeof define==="function"&&define.amd){define([],factory)}else{root.objectPath=factory()}})(this,function(){"use strict";var toStr=Object.prototype.toString,_hasOwnProperty=Object.prototype.hasOwnProperty;function isEmpty(value){if(!value){return true}if(isArray(value)&&value.length===0){return true}else if(!isString(value)){for(var i in value){if(_hasOwnProperty.call(value,i)){return false}}return true}return false}function toString(type){return toStr.call(type)}function isNumber(value){return typeof value==="number"||toString(value)==="[object Number]"}function isString(obj){return typeof obj==="string"||toString(obj)==="[object String]"}function isObject(obj){return typeof obj==="object"&&toString(obj)==="[object Object]"}function isArray(obj){return typeof obj==="object"&&typeof obj.length==="number"&&toString(obj)==="[object Array]"}function isBoolean(obj){return typeof obj==="boolean"||toString(obj)==="[object Boolean]"}function getKey(key){var intKey=parseInt(key);if(intKey.toString()===key){return intKey}return key}function set(obj,path,value,doNotReplace){if(isNumber(path)){path=[path]}if(isEmpty(path)){return obj}if(isString(path)){return set(obj,path.split(".").map(getKey),value,doNotReplace)}var currentPath=path[0];if(path.length===1){var oldVal=obj[currentPath];if(oldVal===void 0||!doNotReplace){obj[currentPath]=value}return oldVal}if(obj[currentPath]===void 0){if(isNumber(path[1])){obj[currentPath]=[]}else{obj[currentPath]={}}}return set(obj[currentPath],path.slice(1),value,doNotReplace)}function del(obj,path){if(isNumber(path)){path=[path]}if(isEmpty(obj)){return void 0}if(isEmpty(path)){return obj}if(isString(path)){return del(obj,path.split("."))}var currentPath=getKey(path[0]);var oldVal=obj[currentPath];if(path.length===1){if(oldVal!==void 0){if(isArray(obj)){obj.splice(currentPath,1)}else{delete obj[currentPath]}}}else{if(obj[currentPath]!==void 0){return del(obj[currentPath],path.slice(1))}}return obj}var objectPath=function(obj){return Object.keys(objectPath).reduce(function(proxy,prop){if(typeof objectPath[prop]==="function"){proxy[prop]=objectPath[prop].bind(objectPath,obj)}return proxy},{})};objectPath.has=function(obj,path){if(isEmpty(obj)){return false}if(isNumber(path)){path=[path]}else if(isString(path)){path=path.split(".")}if(isEmpty(path)||path.length===0){return false}for(var i=0;i<path.length;i++){var j=path[i];if((isObject(obj)||isArray(obj))&&_hasOwnProperty.call(obj,j)){obj=obj[j]}else{return false}}return true};objectPath.ensureExists=function(obj,path,value){return set(obj,path,value,true)};objectPath.set=function(obj,path,value,doNotReplace){return set(obj,path,value,doNotReplace)};objectPath.insert=function(obj,path,value,at){var arr=objectPath.get(obj,path);at=~~at;if(!isArray(arr)){arr=[];objectPath.set(obj,path,arr)}arr.splice(at,0,value)};objectPath.empty=function(obj,path){if(isEmpty(path)){return obj}if(isEmpty(obj)){return void 0}var value,i;if(!(value=objectPath.get(obj,path))){return obj}if(isString(value)){return objectPath.set(obj,path,"")}else if(isBoolean(value)){return objectPath.set(obj,path,false)}else if(isNumber(value)){return objectPath.set(obj,path,0)}else if(isArray(value)){value.length=0}else if(isObject(value)){for(i in value){if(_hasOwnProperty.call(value,i)){delete value[i]}}}else{return objectPath.set(obj,path,null)}};objectPath.push=function(obj,path){var arr=objectPath.get(obj,path);if(!isArray(arr)){arr=[];objectPath.set(obj,path,arr)}arr.push.apply(arr,Array.prototype.slice.call(arguments,2))};objectPath.coalesce=function(obj,paths,defaultValue){var value;for(var i=0,len=paths.length;i<len;i++){if((value=objectPath.get(obj,paths[i]))!==void 0){return value}}return defaultValue};objectPath.get=function(obj,path,defaultValue){if(isNumber(path)){path=[path]}if(isEmpty(path)){return obj}if(isEmpty(obj)){return defaultValue}if(isString(path)){return objectPath.get(obj,path.split("."),defaultValue)}var currentPath=getKey(path[0]);if(path.length===1){if(obj[currentPath]===void 0){return defaultValue}return obj[currentPath]}return objectPath.get(obj[currentPath],path.slice(1),defaultValue)};objectPath.del=function(obj,path){return del(obj,path)};return objectPath})},{}],deku:[function(require,module,exports){exports.tree=exports.scene=exports.deku=require("./application");if(typeof document!=="undefined"){exports.render=require("./render")}exports.renderString=require("./stringify")},{"./application":5,"./render":8,"./stringify":9}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";module.exports=arrayFlatten;function flattenWithDepth(array,result,depth){for(var i=0;i<array.length;i++){var value=array[i];if(depth>0&&Array.isArray(value)){flattenWithDepth(value,result,depth-1)}else{result.push(value)}}return result}function flattenForever(array,result){for(var i=0;i<array.length;i++){var value=array[i];if(Array.isArray(value)){flattenForever(value,result)}else{result.push(value)}}return result}function arrayFlatten(array,depth){if(depth==null){return flattenForever(array,[])}return flattenWithDepth(array,[],depth)}},{}],2:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":3}],3:[function(require,module,exports){module.exports=function(args,slice,sliceEnd){var ret=[];var len=args.length;if(0===len)return ret;var start=slice<0?Math.max(0,slice+len):slice||0;if(sliceEnd!==undefined){len=sliceEnd<0?sliceEnd+len:sliceEnd}while(len-->start){ret[len-start]=args[len]}return ret}},{}],"virtual-element":[function(require,module,exports){var slice=require("sliced");var flatten=require("array-flatten");module.exports=element;function element(type,attributes,children){if(!type){throw new TypeError("element() needs a type.")}if(arguments.length===2&&(typeof attributes==="string"||Array.isArray(attributes))){children=[attributes];attributes={}}if(arguments.length>2){children=slice(arguments,2)}children=children||[];attributes=attributes||{};children=flatten(children,2);children=children.filter(function(i){return typeof i!=="undefined"});return{type:type,children:children,attributes:attributes}}},{"array-flatten":1,sliced:2}]},{},[]);require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;
if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],2:[function(require,module,exports){(function(process){"use strict";var invariant=function(condition,format,a,b,c,d,e,f){if(process.env.NODE_ENV!=="production"){if(format===undefined){throw new Error("invariant requires an error message argument")}}if(!condition){var error;if(format===undefined){error=new Error("Minified exception occurred; use the non-minified dev environment "+"for the full error message and additional helpful warnings.")}else{var args=[a,b,c,d,e,f];var argIndex=0;error=new Error(format.replace(/%s/g,function(){return args[argIndex++]}));error.name="Invariant Violation"}error.framesToPop=1;throw error}};module.exports=invariant}).call(this,require("_process"))},{_process:1}],3:[function(require,module,exports){var slice=require("sliced");var flatten=require("array-flatten");module.exports=element;function element(type,attributes,children){if(!type){throw new TypeError("element() needs a type.")}if(arguments.length===2&&(typeof attributes==="string"||Array.isArray(attributes))){children=[attributes];attributes={}}if(arguments.length>2){children=slice(arguments,2)}children=children||[];attributes=attributes||{};children=flatten(children,2);children=children.filter(function(i){return typeof i!=="undefined"});return{type:type,children:children,attributes:attributes}}},{"array-flatten":4,sliced:5}],4:[function(require,module,exports){"use strict";module.exports=arrayFlatten;function flattenWithDepth(array,result,depth){for(var i=0;i<array.length;i++){var value=array[i];if(depth>0&&Array.isArray(value)){flattenWithDepth(value,result,depth-1)}else{result.push(value)}}return result}function flattenForever(array,result){for(var i=0;i<array.length;i++){var value=array[i];if(Array.isArray(value)){flattenForever(value,result)}else{result.push(value)}}return result}function arrayFlatten(array,depth){if(depth==null){return flattenForever(array,[])}return flattenWithDepth(array,[],depth)}},{}],5:[function(require,module,exports){module.exports=exports=require("./lib/sliced")},{"./lib/sliced":6}],6:[function(require,module,exports){module.exports=function(args,slice,sliceEnd){var ret=[];var len=args.length;if(0===len)return ret;var start=slice<0?Math.max(0,slice+len):slice||0;if(sliceEnd!==undefined){len=sliceEnd<0?sliceEnd+len:sliceEnd}while(len-->start){ret[len-start]=args[len]}return ret}},{}],"deku-timer":[function(require,module,exports){"use strict";var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};Object.defineProperty(exports,"__esModule",{value:true});var _virtualElement=require("virtual-element");var _virtualElement2=_interopRequireDefault(_virtualElement);var _invariant=require("invariant");var _invariant2=_interopRequireDefault(_invariant);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var registry={};function timer(delay){(0,_invariant2.default)(typeof delay==="number"&&delay>0,"[react-timer-hoc] `delay` should be a number greater than 0.");return function TimerHoc(TimedComponent){var initialState=function initialState(){return{tick:0}};function afterMount(component,el,setState){var id=component.id;var startTime=Date.now();var tick=0;registry[id]={stopped:false};function setTimer(component){var id=component.id;var state=component.state;var duration=delay-(registry[id].startTime-Date.now())%delay;registry[id].timer=setTimeout(function(){tick++;setState({tick:tick});if(!registry[id].stopped)setTimer(component)},delay)}setTimer(component)}function _stop(component){var id=component.id;registry[id].stopped=true;clearTimeout(registry[id].timer)}function beforeUnmount(component){var id=component.id;_stop(component);registry[id]=undefined}function render(component){var props=component.props;var state=component.state;var id=component.id;return(0,_virtualElement2.default)(TimedComponent,_extends({},props,{delay:delay,tick:state.tick,stop:function stop(){return _stop(component)}}))}var Timer={initialState:initialState,afterMount:afterMount,beforeUnmount:beforeUnmount,render:render};return Timer}}exports.default=timer},{invariant:2,"virtual-element":3}]},{},[]);var element=require("virtual-element");var deku=require("deku");var timer=require("deku-timer").default;function render(component){var props=component.props;return element("div",{},"Started "+props.tick*props.delay+"ms ago.")}function countdown(component){var props=component.props;if(props.from-props.tick===0)props.stop();return element("div",{},props.from-props.tick)}var Component={render:render};var Timer1=timer(1e3)(Component);var Timer2=timer(2e3)(Component);var Countdown={render:countdown};var Countdown1=timer(1e3)(Countdown);var app=deku.tree(element("div",{},[element(Timer1),element(Timer2),element(Countdown1,{from:20})]));deku.render(app,document.body);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"deku": "0.5.6",
"virtual-element": "1.2.0",
"deku-timer": "1.0.3"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment