made with requirebin
Created
January 14, 2015 13:47
-
-
Save refractalize/15d9e47fe0f906a522b2 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var plastiq = require('plastiq'); | |
var h = plastiq.html; | |
function render(model) { | |
return h('div', | |
h.animation(model.animation.bind(model)), | |
h('div', model.counter) | |
); | |
} | |
plastiq.attach(document.body, render, { | |
animation: function (refresh) { | |
var self = this; | |
setTimeout(function () { | |
self.counter++; | |
refresh(); | |
setTimeout(function () { | |
self.counter++; | |
refresh(); | |
setTimeout(function () { | |
self.counter++; | |
refresh(); | |
}, 500); | |
}, 500); | |
}, 500); | |
}, | |
counter: 0 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){},{}],2:[function(require,module,exports){var rendering=require("./rendering");function AnimationWidget(fn){this.fn=fn;this.refresh=rendering.globalRefresh}AnimationWidget.prototype.type="Widget";AnimationWidget.prototype.init=function(){this.fn(this.refresh);return document.createTextNode("")};AnimationWidget.prototype.update=function(){};AnimationWidget.prototype.destroy=function(){};module.exports=function(fn){return new AnimationWidget(fn)}},{"./rendering":41}],3:[function(require,module,exports){module.exports=function(obj,prop){return{get:function(){return obj[prop]},set:function(value){obj[prop]=value}}}},{}],4:[function(require,module,exports){var vtext=require("virtual-dom/vnode/vtext.js");module.exports=function(child){if(child===undefined||child==null){return undefined}else if(typeof child!="object"){return new vtext(String(child))}else if(child instanceof Date){return new vtext(String(child))}else{return child}}},{"virtual-dom/vnode/vtext.js":37}],5:[function(require,module,exports){var rendering=require("./rendering");var VText=require("virtual-dom/vnode/vtext.js");var domComponent=require("./domComponent");function ComponentWidget(handlers,vdom){this.handlers=handlers;if(typeof vdom==="function"){this.render=vdom}else{vdom=vdom||new VText("");this.render=function(){return vdom}}this.component=domComponent();this.renderFinished=rendering.renderFinished}ComponentWidget.prototype.type="Widget";ComponentWidget.prototype.init=function(){var self=this;var element=this.component.create(this.render());if(self.handlers.onadd){this.renderFinished.then(function(){self.handlers.onadd(element)})}return element};ComponentWidget.prototype.update=function(previous){var self=this;if(self.handlers.onupdate){this.renderFinished.then(function(){self.handlers.onupdate(self.component.element)})}this.component=previous.component;return this.component.update(this.render())};ComponentWidget.prototype.destroy=function(element){var self=this;if(self.handlers.onremove){this.renderFinished.then(function(){self.handlers.onremove(element)})}this.component.destroy()};module.exports=function(handlers,vdom){if(typeof handlers==="function"){return new ComponentWidget({},handlers)}else if(handlers.constructor===Object){return new ComponentWidget(handlers,vdom)}else{return new ComponentWidget({},handlers)}};module.exports.ComponentWidget=ComponentWidget},{"./domComponent":6,"./rendering":41,"virtual-dom/vnode/vtext.js":37}],6:[function(require,module,exports){var createElement=require("virtual-dom/create-element");var diff=require("virtual-dom/diff");var patch=require("virtual-dom/patch");var coerceToVdom=require("./coerceToVdom");function DomComponent(){}DomComponent.prototype.create=function(vdom){vdom=coerceToVdom(vdom);this.vdom=vdom;this.element=createElement(vdom);return this.element};DomComponent.prototype.update=function(vdom){var patches=diff(this.vdom,vdom);this.element=patch(this.element,patches);this.vdom=vdom;return this.element};DomComponent.prototype.destroy=function(){function destroyWidgets(vdom){if(vdom.type==="Widget"){vdom.destroy()}else if(vdom.children){vdom.children.forEach(destroyWidgets)}}destroyWidgets(this.vdom)};function domComponent(){return new DomComponent}module.exports=domComponent},{"./coerceToVdom":4,"virtual-dom/create-element":7,"virtual-dom/diff":8,"virtual-dom/patch":17}],7:[function(require,module,exports){var createElement=require("./vdom/create-element.js");module.exports=createElement},{"./vdom/create-element.js":19}],8:[function(require,module,exports){var diff=require("./vtree/diff.js");module.exports=diff},{"./vtree/diff.js":38}],9:[function(require,module,exports){var h=require("./virtual-hyperscript/index.js");module.exports=h},{"./virtual-hyperscript/index.js":26}],10:[function(require,module,exports){module.exports=function split(undef){var nativeSplit=String.prototype.split,compliantExecNpcg=/()??/.exec("")[1]===undef,self;self=function(str,separator,limit){if(Object.prototype.toString.call(separator)!=="[object RegExp]"){return nativeSplit.call(str,separator,limit)}var output=[],flags=(separator.ignoreCase?"i":"")+(separator.multiline?"m":"")+(separator.extended?"x":"")+(separator.sticky?"y":""),lastLastIndex=0,separator=new RegExp(separator.source,flags+"g"),separator2,match,lastIndex,lastLength;str+="";if(!compliantExecNpcg){separator2=new RegExp("^"+separator.source+"$(?!\\s)",flags)}limit=limit===undef?-1>>>0:limit>>>0;while(match=separator.exec(str)){lastIndex=match.index+match[0].length;if(lastIndex>lastLastIndex){output.push(str.slice(lastLastIndex,match.index));if(!compliantExecNpcg&&match.length>1){match[0].replace(separator2,function(){for(var i=1;i<arguments.length-2;i++){if(arguments[i]===undef){match[i]=undef}}})}if(match.length>1&&match.index<str.length){Array.prototype.push.apply(output,match.slice(1))}lastLength=match[0].length;lastLastIndex=lastIndex;if(output.length>=limit){break}}if(separator.lastIndex===match.index){separator.lastIndex++}}if(lastLastIndex===str.length){if(lastLength||!separator.test("")){output.push("")}}else{output.push(str.slice(lastLastIndex))}return output.length>limit?output.slice(0,limit):output};return self}()},{}],11:[function(require,module,exports){"use strict";var OneVersionConstraint=require("individual/one-version");var MY_VERSION="7";OneVersionConstraint("ev-store",MY_VERSION);var hashKey="__EV_STORE_KEY@"+MY_VERSION;module.exports=EvStore;function EvStore(elem){var hash=elem[hashKey];if(!hash){hash=elem[hashKey]={}}return hash}},{"individual/one-version":13}],12:[function(require,module,exports){(function(global){"use strict";var root=typeof window!=="undefined"?window:typeof global!=="undefined"?global:{};module.exports=Individual;function Individual(key,value){if(key in root){return root[key]}root[key]=value;return value}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],13:[function(require,module,exports){"use strict";var Individual=require("./index.js");module.exports=OneVersion;function OneVersion(moduleName,version,defaultValue){var key="__INDIVIDUAL_ONE_VERSION_"+moduleName;var enforceKey=key+"_ENFORCE_SINGLETON";var versionValue=Individual(enforceKey,version);if(versionValue!==version){throw new Error("Can only have one copy of "+moduleName+".\n"+"You already have version "+versionValue+" installed.\n"+"This means you cannot install version "+version)}return Individual(key,defaultValue)}},{"./index.js":12}],14:[function(require,module,exports){(function(global){var topLevel=typeof global!=="undefined"?global:typeof window!=="undefined"?window:{};var minDoc=require("min-document");if(typeof document!=="undefined"){module.exports=document}else{var doccy=topLevel["__GLOBAL_DOCUMENT_CACHE@4"];if(!doccy){doccy=topLevel["__GLOBAL_DOCUMENT_CACHE@4"]=minDoc}module.exports=doccy}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"min-document":1}],15:[function(require,module,exports){"use strict";module.exports=function isObject(x){return typeof x==="object"&&x!==null}},{}],16:[function(require,module,exports){var nativeIsArray=Array.isArray;var toString=Object.prototype.toString;module.exports=nativeIsArray||isArray;function isArray(obj){return toString.call(obj)==="[object Array]"}},{}],17:[function(require,module,exports){var patch=require("./vdom/patch.js");module.exports=patch},{"./vdom/patch.js":22}],18:[function(require,module,exports){var isObject=require("is-object");var isHook=require("../vnode/is-vhook.js");module.exports=applyProperties;function applyProperties(node,props,previous){for(var propName in props){var propValue=props[propName];if(propValue===undefined){removeProperty(node,props,previous,propName)}else if(isHook(propValue)){propValue.hook(node,propName,previous?previous[propName]:undefined)}else{if(isObject(propValue)){patchObject(node,props,previous,propName,propValue)}else if(propValue!==undefined){node[propName]=propValue}}}}function removeProperty(node,props,previous,propName){if(previous){var previousValue=previous[propName];if(!isHook(previousValue)){if(propName==="attributes"){for(var attrName in previousValue){node.removeAttribute(attrName)}}else if(propName==="style"){for(var i in previousValue){node.style[i]=""}}else if(typeof previousValue==="string"){node[propName]=""}else{node[propName]=null}}else if(previousValue.unhook){previousValue.unhook(node,propName)}}}function patchObject(node,props,previous,propName,propValue){var previousValue=previous?previous[propName]:undefined;if(propName==="attributes"){for(var attrName in propValue){var attrValue=propValue[attrName];if(attrValue===undefined){node.removeAttribute(attrName)}else{node.setAttribute(attrName,attrValue)}}return}if(previousValue&&isObject(previousValue)&&getPrototype(previousValue)!==getPrototype(propValue)){node[propName]=propValue;return}if(!isObject(node[propName])){node[propName]={}}var replacer=propName==="style"?"":undefined;for(var k in propValue){var value=propValue[k];node[propName][k]=value===undefined?replacer:value}}function getPrototype(value){if(Object.getPrototypeOf){return Object.getPrototypeOf(value)}else if(value.__proto__){return value.__proto__}else if(value.constructor){return value.constructor.prototype}}},{"../vnode/is-vhook.js":30,"is-object":15}],19:[function(require,module,exports){var document=require("global/document");var applyProperties=require("./apply-properties");var isVNode=require("../vnode/is-vnode.js");var isVText=require("../vnode/is-vtext.js");var isWidget=require("../vnode/is-widget.js");var handleThunk=require("../vnode/handle-thunk.js");module.exports=createElement;function createElement(vnode,opts){var doc=opts?opts.document||document:document;var warn=opts?opts.warn:null;vnode=handleThunk(vnode).a;if(isWidget(vnode)){return vnode.init()}else if(isVText(vnode)){return doc.createTextNode(vnode.text)}else if(!isVNode(vnode)){if(warn){warn("Item is not a valid virtual dom node",vnode)}return null}var node=vnode.namespace===null?doc.createElement(vnode.tagName):doc.createElementNS(vnode.namespace,vnode.tagName);var props=vnode.properties;applyProperties(node,props);var children=vnode.children;for(var i=0;i<children.length;i++){var childNode=createElement(children[i],opts);if(childNode){node.appendChild(childNode)}}return node}},{"../vnode/handle-thunk.js":28,"../vnode/is-vnode.js":31,"../vnode/is-vtext.js":32,"../vnode/is-widget.js":33,"./apply-properties":18,"global/document":14}],20:[function(require,module,exports){var noChild={};module.exports=domIndex;function domIndex(rootNode,tree,indices,nodes){if(!indices||indices.length===0){return{}}else{indices.sort(ascending);return recurse(rootNode,tree,indices,nodes,0)}}function recurse(rootNode,tree,indices,nodes,rootIndex){nodes=nodes||{};if(rootNode){if(indexInRange(indices,rootIndex,rootIndex)){nodes[rootIndex]=rootNode}var vChildren=tree.children;if(vChildren){var childNodes=rootNode.childNodes;for(var i=0;i<tree.children.length;i++){rootIndex+=1;var vChild=vChildren[i]||noChild;var nextIndex=rootIndex+(vChild.count||0);if(indexInRange(indices,rootIndex,nextIndex)){recurse(childNodes[i],vChild,indices,nodes,rootIndex)}rootIndex=nextIndex}}}return nodes}function indexInRange(indices,left,right){if(indices.length===0){return false}var minIndex=0;var maxIndex=indices.length-1;var currentIndex;var currentItem;while(minIndex<=maxIndex){currentIndex=(maxIndex+minIndex)/2>>0;currentItem=indices[currentIndex];if(minIndex===maxIndex){return currentItem>=left&¤tItem<=right}else if(currentItem<left){minIndex=currentIndex+1}else if(currentItem>right){maxIndex=currentIndex-1}else{return true}}return false}function ascending(a,b){return a>b?1:-1}},{}],21:[function(require,module,exports){var applyProperties=require("./apply-properties");var isWidget=require("../vnode/is-widget.js");var VPatch=require("../vnode/vpatch.js");var render=require("./create-element");var updateWidget=require("./update-widget");module.exports=applyPatch;function applyPatch(vpatch,domNode,renderOptions){var type=vpatch.type;var vNode=vpatch.vNode;var patch=vpatch.patch;switch(type){case VPatch.REMOVE:return removeNode(domNode,vNode);case VPatch.INSERT:return insertNode(domNode,patch,renderOptions);case VPatch.VTEXT:return stringPatch(domNode,vNode,patch,renderOptions);case VPatch.WIDGET:return widgetPatch(domNode,vNode,patch,renderOptions);case VPatch.VNODE:return vNodePatch(domNode,vNode,patch,renderOptions);case VPatch.ORDER:reorderChildren(domNode,patch);return domNode;case VPatch.PROPS:applyProperties(domNode,patch,vNode.properties);return domNode;case VPatch.THUNK:return replaceRoot(domNode,renderOptions.patch(domNode,patch,renderOptions));default:return domNode}}function removeNode(domNode,vNode){var parentNode=domNode.parentNode;if(parentNode){parentNode.removeChild(domNode)}destroyWidget(domNode,vNode);return null}function insertNode(parentNode,vNode,renderOptions){var newNode=render(vNode,renderOptions);if(parentNode){parentNode.appendChild(newNode)}return parentNode}function stringPatch(domNode,leftVNode,vText,renderOptions){var newNode;if(domNode.nodeType===3){domNode.replaceData(0,domNode.length,vText.text);newNode=domNode}else{var parentNode=domNode.parentNode;newNode=render(vText,renderOptions);if(parentNode){parentNode.replaceChild(newNode,domNode)}}return newNode}function widgetPatch(domNode,leftVNode,widget,renderOptions){var updating=updateWidget(leftVNode,widget);var newNode;if(updating){newNode=widget.update(leftVNode,domNode)||domNode}else{newNode=render(widget,renderOptions)}var parentNode=domNode.parentNode;if(parentNode&&newNode!==domNode){parentNode.replaceChild(newNode,domNode)}if(!updating){destroyWidget(domNode,leftVNode)}return newNode}function vNodePatch(domNode,leftVNode,vNode,renderOptions){var parentNode=domNode.parentNode;var newNode=render(vNode,renderOptions);if(parentNode){parentNode.replaceChild(newNode,domNode)}return newNode}function destroyWidget(domNode,w){if(typeof w.destroy==="function"&&isWidget(w)){w.destroy(domNode)}}function reorderChildren(domNode,bIndex){var children=[];var childNodes=domNode.childNodes;var len=childNodes.length;var i;var reverseIndex=bIndex.reverse;for(i=0;i<len;i++){children.push(domNode.childNodes[i])}var insertOffset=0;var move;var node;var insertNode;var chainLength;var insertedLength;var nextSibling;for(i=0;i<len;){move=bIndex[i];chainLength=1;if(move!==undefined&&move!==i){while(bIndex[i+chainLength]===move+chainLength){chainLength++}if(reverseIndex[i]>i+chainLength){insertOffset++}node=children[move];insertNode=childNodes[i+insertOffset]||null;insertedLength=0;while(node!==insertNode&&insertedLength++<chainLength){domNode.insertBefore(node,insertNode);node=children[move+insertedLength]}if(move+chainLength<i){insertOffset--}}if(i in bIndex.removes){insertOffset++}i+=chainLength}}function replaceRoot(oldRoot,newRoot){if(oldRoot&&newRoot&&oldRoot!==newRoot&&oldRoot.parentNode){console.log(oldRoot);oldRoot.parentNode.replaceChild(newRoot,oldRoot)}return newRoot}},{"../vnode/is-widget.js":33,"../vnode/vpatch.js":36,"./apply-properties":18,"./create-element":19,"./update-widget":23}],22:[function(require,module,exports){var document=require("global/document");var isArray=require("x-is-array");var domIndex=require("./dom-index");var patchOp=require("./patch-op");module.exports=patch;function patch(rootNode,patches){return patchRecursive(rootNode,patches)}function patchRecursive(rootNode,patches,renderOptions){var indices=patchIndices(patches);if(indices.length===0){return rootNode}var index=domIndex(rootNode,patches.a,indices);var ownerDocument=rootNode.ownerDocument;if(!renderOptions){renderOptions={patch:patchRecursive};if(ownerDocument!==document){renderOptions.document=ownerDocument}}for(var i=0;i<indices.length;i++){var nodeIndex=indices[i];rootNode=applyPatch(rootNode,index[nodeIndex],patches[nodeIndex],renderOptions)}return rootNode}function applyPatch(rootNode,domNode,patchList,renderOptions){if(!domNode){return rootNode}var newNode;if(isArray(patchList)){for(var i=0;i<patchList.length;i++){newNode=patchOp(patchList[i],domNode,renderOptions);if(domNode===rootNode){rootNode=newNode}}}else{newNode=patchOp(patchList,domNode,renderOptions);if(domNode===rootNode){rootNode=newNode}}return rootNode}function patchIndices(patches){var indices=[];for(var key in patches){if(key!=="a"){indices.push(Number(key))}}return indices}},{"./dom-index":20,"./patch-op":21,"global/document":14,"x-is-array":16}],23:[function(require,module,exports){var isWidget=require("../vnode/is-widget.js");module.exports=updateWidget;function updateWidget(a,b){if(isWidget(a)&&isWidget(b)){if("name"in a&&"name"in b){return a.id===b.id}else{return a.init===b.init}}return false}},{"../vnode/is-widget.js":33}],24:[function(require,module,exports){"use strict";var EvStore=require("ev-store");module.exports=EvHook;function EvHook(value){if(!(this instanceof EvHook)){return new EvHook(value)}this.value=value}EvHook.prototype.hook=function(node,propertyName){var es=EvStore(node);var propName=propertyName.substr(3);es[propName]=this.value};EvHook.prototype.unhook=function(node,propertyName){var es=EvStore(node);var propName=propertyName.substr(3);es[propName]=undefined}},{"ev-store":11}],25:[function(require,module,exports){"use strict";module.exports=SoftSetHook;function SoftSetHook(value){if(!(this instanceof SoftSetHook)){return new SoftSetHook(value)}this.value=value}SoftSetHook.prototype.hook=function(node,propertyName){if(node[propertyName]!==this.value){node[propertyName]=this.value}}},{}],26:[function(require,module,exports){"use strict";var isArray=require("x-is-array");var VNode=require("../vnode/vnode.js");var VText=require("../vnode/vtext.js");var isVNode=require("../vnode/is-vnode");var isVText=require("../vnode/is-vtext");var isWidget=require("../vnode/is-widget");var isHook=require("../vnode/is-vhook");var isVThunk=require("../vnode/is-thunk");var parseTag=require("./parse-tag.js");var softSetHook=require("./hooks/soft-set-hook.js");var evHook=require("./hooks/ev-hook.js");module.exports=h;function h(tagName,properties,children){var childNodes=[];var tag,props,key,namespace;if(!children&&isChildren(properties)){children=properties;props={}}props=props||properties||{};tag=parseTag(tagName,props);if(props.hasOwnProperty("key")){key=props.key;props.key=undefined}if(props.hasOwnProperty("namespace")){namespace=props.namespace;props.namespace=undefined}if(tag==="INPUT"&&!namespace&&props.hasOwnProperty("value")&&props.value!==undefined&&!isHook(props.value)){props.value=softSetHook(props.value)}transformProperties(props);if(children!==undefined&&children!==null){addChild(children,childNodes,tag,props)}return new VNode(tag,props,childNodes,key,namespace)}function addChild(c,childNodes,tag,props){if(typeof c==="string"){childNodes.push(new VText(c))}else if(isChild(c)){childNodes.push(c)}else if(isArray(c)){for(var i=0;i<c.length;i++){addChild(c[i],childNodes,tag,props)}}else if(c===null||c===undefined){return}else{throw UnexpectedVirtualElement({foreignObject:c,parentVnode:{tagName:tag,properties:props}})}}function transformProperties(props){for(var propName in props){if(props.hasOwnProperty(propName)){var value=props[propName];if(isHook(value)){continue}if(propName.substr(0,3)==="ev-"){props[propName]=evHook(value)}}}}function isChild(x){return isVNode(x)||isVText(x)||isWidget(x)||isVThunk(x)}function isChildren(x){return typeof x==="string"||isArray(x)||isChild(x)}function UnexpectedVirtualElement(data){var err=new Error;err.type="virtual-hyperscript.unexpected.virtual-element";err.message="Unexpected virtual child passed to h().\n"+"Expected a VNode / Vthunk / VWidget / string but:\n"+"got:\n"+errorString(data.foreignObject)+".\n"+"The parent vnode is:\n"+errorString(data.parentVnode);"\n"+"Suggested fix: change your `h(..., [ ... ])` callsite.";err.foreignObject=data.foreignObject;err.parentVnode=data.parentVnode;return err}function errorString(obj){try{return JSON.stringify(obj,null," ")}catch(e){return String(obj)}}},{"../vnode/is-thunk":29,"../vnode/is-vhook":30,"../vnode/is-vnode":31,"../vnode/is-vtext":32,"../vnode/is-widget":33,"../vnode/vnode.js":35,"../vnode/vtext.js":37,"./hooks/ev-hook.js":24,"./hooks/soft-set-hook.js":25,"./parse-tag.js":27,"x-is-array":16}],27:[function(require,module,exports){"use strict";var split=require("browser-split");var classIdSplit=/([\.#]?[a-zA-Z0-9_:-]+)/;var notClassId=/^\.|#/;module.exports=parseTag;function parseTag(tag,props){if(!tag){return"DIV"}var noId=!props.hasOwnProperty("id");var tagParts=split(tag,classIdSplit);var tagName=null;if(notClassId.test(tagParts[1])){tagName="DIV"}var classes,part,type,i;for(i=0;i<tagParts.length;i++){part=tagParts[i];if(!part){continue}type=part.charAt(0);if(!tagName){tagName=part}else if(type==="."){classes=classes||[];classes.push(part.substring(1,part.length))}else if(type==="#"&&noId){props.id=part.substring(1,part.length)}}if(classes){if(props.className){classes.push(props.className)}props.className=classes.join(" ")}return props.namespace?tagName:tagName.toUpperCase()}},{"browser-split":10}],28:[function(require,module,exports){var isVNode=require("./is-vnode");var isVText=require("./is-vtext");var isWidget=require("./is-widget");var isThunk=require("./is-thunk");module.exports=handleThunk;function handleThunk(a,b){var renderedA=a;var renderedB=b;if(isThunk(b)){renderedB=renderThunk(b,a)}if(isThunk(a)){renderedA=renderThunk(a,null)}return{a:renderedA,b:renderedB}}function renderThunk(thunk,previous){var renderedThunk=thunk.vnode;if(!renderedThunk){renderedThunk=thunk.vnode=thunk.render(previous)}if(!(isVNode(renderedThunk)||isVText(renderedThunk)||isWidget(renderedThunk))){throw new Error("thunk did not return a valid node")}return renderedThunk}},{"./is-thunk":29,"./is-vnode":31,"./is-vtext":32,"./is-widget":33}],29:[function(require,module,exports){module.exports=isThunk;function isThunk(t){return t&&t.type==="Thunk"}},{}],30:[function(require,module,exports){module.exports=isHook;function isHook(hook){return hook&&typeof hook.hook==="function"&&!hook.hasOwnProperty("hook")}},{}],31:[function(require,module,exports){var version=require("./version");module.exports=isVirtualNode;function isVirtualNode(x){return x&&x.type==="VirtualNode"&&x.version===version}},{"./version":34}],32:[function(require,module,exports){var version=require("./version");module.exports=isVirtualText;function isVirtualText(x){return x&&x.type==="VirtualText"&&x.version===version}},{"./version":34}],33:[function(require,module,exports){module.exports=isWidget;function isWidget(w){return w&&w.type==="Widget"}},{}],34:[function(require,module,exports){module.exports="1"},{}],35:[function(require,module,exports){var version=require("./version");var isVNode=require("./is-vnode");var isWidget=require("./is-widget");var isThunk=require("./is-thunk");var isVHook=require("./is-vhook");module.exports=VirtualNode;var noProperties={};var noChildren=[];function VirtualNode(tagName,properties,children,key,namespace){this.tagName=tagName;this.properties=properties||noProperties;this.children=children||noChildren;this.key=key!=null?String(key):undefined;this.namespace=typeof namespace==="string"?namespace:null;var count=children&&children.length||0;var descendants=0;var hasWidgets=false;var hasThunks=false;var descendantHooks=false;var hooks;for(var propName in properties){if(properties.hasOwnProperty(propName)){var property=properties[propName];if(isVHook(property)&&property.unhook){if(!hooks){hooks={}}hooks[propName]=property}}}for(var i=0;i<count;i++){var child=children[i];if(isVNode(child)){descendants+=child.count||0;if(!hasWidgets&&child.hasWidgets){hasWidgets=true}if(!hasThunks&&child.hasThunks){hasThunks=true}if(!descendantHooks&&(child.hooks||child.descendantHooks)){descendantHooks=true}}else if(!hasWidgets&&isWidget(child)){if(typeof child.destroy==="function"){hasWidgets=true}}else if(!hasThunks&&isThunk(child)){hasThunks=true}}this.count=count+descendants;this.hasWidgets=hasWidgets;this.hasThunks=hasThunks;this.hooks=hooks;this.descendantHooks=descendantHooks}VirtualNode.prototype.version=version;VirtualNode.prototype.type="VirtualNode"},{"./is-thunk":29,"./is-vhook":30,"./is-vnode":31,"./is-widget":33,"./version":34}],36:[function(require,module,exports){var version=require("./version");VirtualPatch.NONE=0;VirtualPatch.VTEXT=1;VirtualPatch.VNODE=2;VirtualPatch.WIDGET=3;VirtualPatch.PROPS=4;VirtualPatch.ORDER=5;VirtualPatch.INSERT=6;VirtualPatch.REMOVE=7;VirtualPatch.THUNK=8;module.exports=VirtualPatch;function VirtualPatch(type,vNode,patch){this.type=Number(type);this.vNode=vNode;this.patch=patch}VirtualPatch.prototype.version=version;VirtualPatch.prototype.type="VirtualPatch"},{"./version":34}],37:[function(require,module,exports){var version=require("./version");module.exports=VirtualText;function VirtualText(text){this.text=String(text)}VirtualText.prototype.version=version;VirtualText.prototype.type="VirtualText"},{"./version":34}],38:[function(require,module,exports){var isArray=require("x-is-array");var isObject=require("is-object");var VPatch=require("../vnode/vpatch");var isVNode=require("../vnode/is-vnode");var isVText=require("../vnode/is-vtext");var isWidget=require("../vnode/is-widget");var isThunk=require("../vnode/is-thunk");var isHook=require("../vnode/is-vhook");var handleThunk=require("../vnode/handle-thunk");module.exports=diff;function diff(a,b){var patch={a:a};walk(a,b,patch,0);return patch}function walk(a,b,patch,index){if(a===b){return}var apply=patch[index];var applyClear=false;if(isThunk(a)||isThunk(b)){thunks(a,b,patch,index)}else if(b==null){if(!isWidget(a)){clearState(a,patch,index);apply=patch[index]}apply=appendPatch(apply,new VPatch(VPatch.REMOVE,a,b))}else if(isVNode(b)){if(isVNode(a)){if(a.tagName===b.tagName&&a.namespace===b.namespace&&a.key===b.key){var propsPatch=diffProps(a.properties,b.properties);if(propsPatch){apply=appendPatch(apply,new VPatch(VPatch.PROPS,a,propsPatch))}apply=diffChildren(a,b,patch,apply,index)}else{apply=appendPatch(apply,new VPatch(VPatch.VNODE,a,b));applyClear=true}}else{apply=appendPatch(apply,new VPatch(VPatch.VNODE,a,b));applyClear=true}}else if(isVText(b)){if(!isVText(a)){apply=appendPatch(apply,new VPatch(VPatch.VTEXT,a,b));applyClear=true}else if(a.text!==b.text){apply=appendPatch(apply,new VPatch(VPatch.VTEXT,a,b))}}else if(isWidget(b)){if(!isWidget(a)){applyClear=true}apply=appendPatch(apply,new VPatch(VPatch.WIDGET,a,b))}if(apply){patch[index]=apply}if(applyClear){clearState(a,patch,index)}}function diffProps(a,b){var diff;for(var aKey in a){if(!(aKey in b)){diff=diff||{};diff[aKey]=undefined}var aValue=a[aKey];var bValue=b[aKey];if(aValue===bValue){continue}else if(isObject(aValue)&&isObject(bValue)){if(getPrototype(bValue)!==getPrototype(aValue)){diff=diff||{};diff[aKey]=bValue}else if(isHook(bValue)){diff=diff||{};diff[aKey]=bValue}else{var objectDiff=diffProps(aValue,bValue);if(objectDiff){diff=diff||{};diff[aKey]=objectDiff}}}else{diff=diff||{};diff[aKey]=bValue}}for(var bKey in b){if(!(bKey in a)){diff=diff||{};diff[bKey]=b[bKey]}}return diff}function getPrototype(value){if(Object.getPrototypeOf){return Object.getPrototypeOf(value)}else if(value.__proto__){return value.__proto__}else if(value.constructor){return value.constructor.prototype}}function diffChildren(a,b,patch,apply,index){var aChildren=a.children;var bChildren=reorder(aChildren,b.children);var aLen=aChildren.length;var bLen=bChildren.length;var len=aLen>bLen?aLen:bLen;for(var i=0;i<len;i++){var leftNode=aChildren[i];var rightNode=bChildren[i];index+=1;if(!leftNode){if(rightNode){apply=appendPatch(apply,new VPatch(VPatch.INSERT,null,rightNode))}}else{walk(leftNode,rightNode,patch,index)}if(isVNode(leftNode)&&leftNode.count){index+=leftNode.count}}if(bChildren.moves){apply=appendPatch(apply,new VPatch(VPatch.ORDER,a,bChildren.moves))}return apply}function clearState(vNode,patch,index){unhook(vNode,patch,index);destroyWidgets(vNode,patch,index)}function destroyWidgets(vNode,patch,index){if(isWidget(vNode)){if(typeof vNode.destroy==="function"){patch[index]=appendPatch(patch[index],new VPatch(VPatch.REMOVE,vNode,null))}}else if(isVNode(vNode)&&(vNode.hasWidgets||vNode.hasThunks)){var children=vNode.children;var len=children.length;for(var i=0;i<len;i++){var child=children[i];index+=1;destroyWidgets(child,patch,index);if(isVNode(child)&&child.count){index+=child.count}}}else if(isThunk(vNode)){thunks(vNode,null,patch,index)}}function thunks(a,b,patch,index){var nodes=handleThunk(a,b);var thunkPatch=diff(nodes.a,nodes.b);if(hasPatches(thunkPatch)){patch[index]=new VPatch(VPatch.THUNK,null,thunkPatch)}}function hasPatches(patch){for(var index in patch){if(index!=="a"){return true}}return false}function unhook(vNode,patch,index){if(isVNode(vNode)){if(vNode.hooks){patch[index]=appendPatch(patch[index],new VPatch(VPatch.PROPS,vNode,undefinedKeys(vNode.hooks)))}if(vNode.descendantHooks||vNode.hasThunks){var children=vNode.children;var len=children.length;for(var i=0;i<len;i++){var child=children[i];index+=1;unhook(child,patch,index);if(isVNode(child)&&child.count){index+=child.count}}}}else if(isThunk(vNode)){thunks(vNode,null,patch,index)}}function undefinedKeys(obj){var result={};for(var key in obj){result[key]=undefined}return result}function reorder(aChildren,bChildren){var bKeys=keyIndex(bChildren);if(!bKeys){return bChildren}var aKeys=keyIndex(aChildren);if(!aKeys){return bChildren}var bMatch={},aMatch={};for(var aKey in bKeys){bMatch[bKeys[aKey]]=aKeys[aKey]}for(var bKey in aKeys){aMatch[aKeys[bKey]]=bKeys[bKey]}var aLen=aChildren.length;var bLen=bChildren.length;var len=aLen>bLen?aLen:bLen;var shuffle=[];var freeIndex=0;var i=0;var moveIndex=0;var moves={};var removes=moves.removes={};var reverse=moves.reverse={};var hasMoves=false;while(freeIndex<len){var move=aMatch[i];if(move!==undefined){shuffle[i]=bChildren[move];if(move!==moveIndex){moves[move]=moveIndex;reverse[moveIndex]=move;hasMoves=true}moveIndex++}else if(i in aMatch){shuffle[i]=undefined;removes[i]=moveIndex++;hasMoves=true}else{while(bMatch[freeIndex]!==undefined){freeIndex++}if(freeIndex<len){var freeChild=bChildren[freeIndex];if(freeChild){shuffle[i]=freeChild;if(freeIndex!==moveIndex){hasMoves=true;moves[freeIndex]=moveIndex;reverse[moveIndex]=freeIndex}moveIndex++}freeIndex++}}i++}if(hasMoves){shuffle.moves=moves}return shuffle}function keyIndex(children){var i,keys;for(i=0;i<children.length;i++){var child=children[i];if(child.key!==undefined){keys=keys||{};keys[child.key]=i}}return keys}function appendPatch(apply,patch){if(apply){if(isArray(apply)){apply.push(patch)}else{apply=[apply,patch]}return apply}else{return patch}}},{"../vnode/handle-thunk":28,"../vnode/is-thunk":29,"../vnode/is-vhook":30,"../vnode/is-vnode":31,"../vnode/is-vtext":32,"../vnode/is-widget":33,"../vnode/vpatch":36,"is-object":15,"x-is-array":16}],39:[function(require,module,exports){var rendering=require("./rendering");var createElement=require("virtual-dom/create-element");var coerceToVdom=require("./coerceToVdom");var domComponent=require("./domComponent");function PromiseWidget(promise,handlers){this.promise=promise;this.handlers=handlers;this.refresh=rendering.globalRefresh;this.component=domComponent()}function runPromiseHandler(handlers,handler,value){if(typeof handler=="function"){return coerceToVdom(handler.call(handlers,value))}else if(handler===null||handler===undefined){return coerceToVdom("") | |
}else{return coerceToVdom(handler)}}PromiseWidget.prototype.type="Widget";PromiseWidget.prototype.init=function(){var self=this;if(this.promise&&typeof this.promise.then==="function"){this.promise.then(function(value){self.fulfilled=true;self.value=value;self.refresh()},function(reason){self.rejected=true;self.reason=reason;self.refresh()});return this.component.create(runPromiseHandler(this.handlers,this.handlers.pending))}else{self.fulfilled=true;self.value=this.promise;return this.component.create(runPromiseHandler(this.handlers,this.handlers.fulfilled,this.value))}};PromiseWidget.prototype.update=function(previous){if(previous.promise===this.promise&&(previous.rejected||previous.fulfilled)){this.fulfilled=previous.fulfilled;this.value=previous.value;this.rejected=previous.rejected;this.reason=previous.reason;this.component=previous.component}else{return this.init()}if(this.fulfilled){return this.component.update(runPromiseHandler(this.handlers,this.handlers.fulfilled,this.value))}else if(this.rejected){return this.component.update(runPromiseHandler(this.handlers,this.handlers.rejected,this.reason))}};PromiseWidget.prototype.destroy=function(){this.component.destroy()};module.exports=function(promise,handlers){return new PromiseWidget(promise,handlers)}},{"./coerceToVdom":4,"./domComponent":6,"./rendering":41,"virtual-dom/create-element":7}],40:[function(require,module,exports){var createElement=require("virtual-dom/create-element");var rendering=require("./rendering");function RawHtmlWidget(selector,options,html){this.selector=selector;this.options=options;this.html=html}RawHtmlWidget.prototype.type="Widget";RawHtmlWidget.prototype.init=function(){var element=createElement(rendering.html(this.selector,this.options));element.innerHTML=this.html;return element};RawHtmlWidget.prototype.update=function(previous,element){element.parentNode.replaceChild(this.init(),element)};RawHtmlWidget.prototype.destroy=function(element){};module.exports=function(selector,options,html){if(arguments.length==2){return new RawHtmlWidget(selector,undefined,options)}else{return new RawHtmlWidget(selector,options,html)}}},{"./rendering":41,"virtual-dom/create-element":7}],41:[function(require,module,exports){var h=require("virtual-dom/h");var bind=require("./bind");var domComponent=require("./domComponent");var simplePromise=require("./simplePromise");var coerceToVdom=require("./coerceToVdom");var ComponentWidget=require("./component").ComponentWidget;exports.globalRefresh;function renderWithRefresh(render,model,refresh){var tree;try{exports.globalRefresh=refresh;tree=render(model)}finally{exports.globalRefresh=undefined}return tree}function doThenFireAfterRender(fn){try{exports.renderFinished=simplePromise();fn()}finally{exports.renderFinished.fulfill();exports.renderFinished=undefined}}exports.attach=function(element,render,model,options){var requestRender=options&&options.requestRender||window.requestAnimationFrame||setTimeout;var requested=false;function refresh(){if(!requested){requestRender(function(){requested=false;doThenFireAfterRender(function(){var vdom=renderWithRefresh(render,model,refresh);component.update(vdom)})});requested=true}}var component=domComponent();doThenFireAfterRender(function(){var vdom=renderWithRefresh(render,model,refresh);element.appendChild(component.create(vdom))})};function refreshifyEventHandler(fn){var r=exports.globalRefresh;return function(){var result=fn.apply(undefined,arguments);if(result&&typeof result=="function"){result(r)}else if(result&&typeof result.then=="function"){result.then(r,r)}else if(result instanceof ComponentWidget){result.update(result)}else{r();return result}}}exports.refreshifyEventHandler=refreshifyEventHandler;function bindTextInput(attributes,children,get,set){var textEventNames=["onkeydown","oninput","onpaste","textInput"];attributes.value=get();attachEventHandler(attributes,textEventNames,function(ev){set(ev.target.value)})}function sequenceFunctions(handler1,handler2){return function(ev){handler1(ev);return handler2(ev)}}function insertEventHandler(attributes,eventName,handler){var previousHandler=attributes[eventName];if(previousHandler){attributes[eventName]=sequenceFunctions(handler,previousHandler)}else{attributes[eventName]=handler}}function attachEventHandler(attributes,eventNames,handler){if(eventNames instanceof Array){eventNames.forEach(function(eventName){insertEventHandler(attributes,eventName,handler)})}else{insertEventHandler(attributes,eventNames,handler)}}function bindModel(attributes,children,type){var inputTypeBindings={text:bindTextInput,textarea:bindTextInput,checkbox:function(attributes,children,get,set){attributes.checked=get();attachEventHandler(attributes,"onclick",function(ev){set(ev.target.checked)})},radio:function(attributes,children,get,set){var value=attributes.value;attributes.checked=get()==attributes.value;attachEventHandler(attributes,"onclick",function(ev){set(value)})},select:function(attributes,children,get,set){var currentValue=get();var options=children.filter(function(child){return child.tagName.toLowerCase()=="option"});var selectedOption=options.filter(function(child){return child.properties.value==currentValue})[0];var values=options.map(function(option){return option.properties.value});options.forEach(function(option,index){option.properties.selected=option==selectedOption;option.properties.value=index});attachEventHandler(attributes,"onchange",function(ev){set(values[ev.target.value])})},file:function(attributes,children,get,set){var multiple=attributes.multiple;attachEventHandler(attributes,"onchange",function(ev){if(multiple){set(ev.target.files)}else{set(ev.target.files[0])}})}};var binding=inputTypeBindings[type]||bindTextInput;var bindingAttr=attributes.binding;if(bindingAttr instanceof Array){bindingAttr=bind(bindingAttr[0],bindingAttr[1])}binding(attributes,children,bindingAttr.get,refreshifyEventHandler(bindingAttr.set))}function inputType(selector,attributes){if(/^textarea\b/i.test(selector)){return"textarea"}else if(/^select\b/i.test(selector)){return"select"}else{return attributes.type||"text"}}function flatten(array){var flatArray=[];function append(array){array.forEach(function(item){if(item instanceof Array){append(item)}else{flatArray.push(item)}})}append(array);return flatArray}function coerceChildren(children){return children.map(coerceToVdom)}function applyAttributeRenames(attributes){var renames={"for":"htmlFor","class":"className"};Object.keys(renames).forEach(function(key){if(attributes[key]!==undefined){attributes[renames[key]]=attributes[key]}})}exports.html=function(selector){var attributes;var childElements;if(arguments[1]&&arguments[1].constructor==Object){attributes=arguments[1];childElements=coerceChildren(flatten(Array.prototype.slice.call(arguments,2)));Object.keys(attributes).forEach(function(key){if(typeof attributes[key]=="function"){attributes[key]=refreshifyEventHandler(attributes[key])}});applyAttributeRenames(attributes);if(attributes.className){attributes.className=generateClassName(attributes.className)}if(attributes.binding){bindModel(attributes,childElements,inputType(selector,attributes))}return h.call(undefined,selector,attributes,childElements)}else{childElements=coerceChildren(flatten(Array.prototype.slice.call(arguments,1)));return h.call(undefined,selector,childElements)}};function generateClassName(obj){if(typeof obj=="object"){if(obj instanceof Array){return obj.join(" ")}else{return Object.keys(obj).filter(function(key){return obj[key]}).join(" ")}}else{return obj}}},{"./bind":3,"./coerceToVdom":4,"./component":5,"./domComponent":6,"./simplePromise":42,"virtual-dom/h":9}],42:[function(require,module,exports){function SimplePromise(){this.listeners=[]}SimplePromise.prototype.fulfill=function(value){if(!this.isFulfilled){this.isFulfilled=true;this.value=value;this.listeners.forEach(function(listener){try{listener()}catch(e){}})}};SimplePromise.prototype.then=function(success){if(this.isFulfilled){var self=this;setTimeout(function(){try{success(self.value)}catch(e){}})}else{this.listeners.push(success)}};module.exports=function(){return new SimplePromise}},{}],43:[function(require,module,exports){function WindowWidget(attributes,refreshFunction){this.attributes=attributes;var self=this;this.cache={};Object.keys(this.attributes).forEach(function(key){self.cache[key]=refreshFunction(self.attributes[key])})}function applyAttribute(attributes,name,element){if(/^on/.test(name)){element.addEventListener(name.substr(2),this[name])}}WindowWidget.prototype.type="Widget";WindowWidget.prototype.init=function(){applyPropertyDiffs(window,{},this.attributes,{},this.cache);return document.createTextNode("")};function uniq(array){var sortedArray=array.slice();sortedArray.sort();var last;for(var n=0;n<sortedArray.length;){var current=sortedArray[n];if(last===current){sortedArray.splice(n,1)}else{n++}last=current}return sortedArray}function applyPropertyDiffs(element,previous,current,previousCache,currentCache){uniq(Object.keys(previous).concat(Object.keys(current))).forEach(function(key){if(/^on/.test(key)){var event=key.slice(2);var prev=previous[key];var curr=current[key];var refreshPrev=previousCache[key];var refreshCurr=currentCache[key];if(prev!==undefined&&curr===undefined){element.removeEventListener(event,refreshPrev)}else if(prev!==undefined&&curr!==undefined&&prev!==curr){element.removeEventListener(event,refreshPrev);element.addEventListener(event,refreshCurr)}else if(prev===undefined&&curr!==undefined){element.addEventListener(event,refreshCurr)}}})}WindowWidget.prototype.update=function(previous){var self=this;applyPropertyDiffs(window,previous.attributes,this.attributes,previous.cache,this.cache)};WindowWidget.prototype.destroy=function(){applyPropertyDiffs(window,this.attributes,{},this.cache,{})};module.exports=function(attributes,refreshFunction){return new WindowWidget(attributes,refreshFunction)}},{}],plastiq:[function(require,module,exports){var rendering=require("./rendering");exports.html=rendering.html;exports.attach=rendering.attach;exports.bind=require("./bind");var windowEvents=require("./windowEvents");exports.html.window=function(attributes){return windowEvents(attributes,rendering.refreshifyEventHandler)};exports.html.rawHtml=require("./rawHtml");exports.html.component=require("./component");exports.html.promise=require("./promise");exports.html.animation=require("./animation")},{"./animation":2,"./bind":3,"./component":5,"./promise":39,"./rawHtml":40,"./rendering":41,"./windowEvents":43}]},{},[]);var plastiq=require("plastiq");var h=plastiq.html;function render(model){return h("div",h.animation(model.animation.bind(model)),h("div",model.counter))}plastiq.attach(document.body,render,{animation:function(refresh){var self=this;setTimeout(function(){self.counter++;refresh();setTimeout(function(){self.counter++;refresh();setTimeout(function(){self.counter++;refresh()},500)},500)},500)},counter:0}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"plastiq": "1.6.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment