made with requirebin
Last active
November 5, 2015 19:09
-
-
Save marcelklehr/3159f2144cedb4b1641f to your computer and use it in GitHub Desktop.
requirebin example of a virtual-dom UI hook
This file contains hidden or 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 ObservStruct = require('observ-struct') | |
, ObservArray = require('observ-array') | |
, Computed = require('observ/computed') | |
, vdom = require('virtual-dom') | |
, h = vdom.h | |
var state = ObservStruct({ | |
users: ObservArray([ | |
ObservStruct({id: 0, name: 'foo'}) | |
, ObservStruct({id:1, name: 'bar'}) | |
]) | |
}) | |
var hooks = { | |
user: ObserveArray([]) | |
} | |
function renderableApp() { | |
return Computed([renderableUsers()], function(users) { | |
return h('div.app',[ | |
h('h1', 'A list of users') | |
, users | |
]) | |
}) | |
} | |
function renderableUsers() { | |
return Computed([state.users.map(renderableUser)], function(users) { | |
return h('div.user-list', [ | |
users | |
]) | |
}) | |
} | |
function renderableUser(user) { | |
return Computed([user, hooks.user], function(user, hook) { | |
return h('div.user', [ | |
user.name | |
].concat(hook)) | |
}) | |
} | |
// main | |
var app = renderableApp() | |
, tree = app() | |
, rootNode = vdom.create(tree) | |
document.body.appendChild(rootNode) | |
app(function(newTree) { | |
var patches = vdom.diff(tree, newTree) | |
vdom.patch(rootNode, patches) | |
tree = newTree | |
}) |
This file contains hidden or 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){var setNonEnumerable=require("./lib/set-non-enumerable.js");module.exports=addListener;function addListener(observArray,observ){var list=observArray._list;return observ(function(value){var valueList=observArray().slice();var index=list.indexOf(observ);if(index===-1){var message="observ-array: Unremoved observ listener";var err=new Error(message);err.list=list;err.index=index;err.observ=observ;throw err}valueList.splice(index,1,value);setNonEnumerable(valueList,"_diff",[[index,1,value]]);observArray._observSet(valueList)})}},{"./lib/set-non-enumerable.js":6}],2:[function(require,module,exports){var addListener=require("./add-listener.js");module.exports=applyPatch;function applyPatch(valueList,args){var obs=this;var valueArgs=args.map(unpack);valueList.splice.apply(valueList,valueArgs);obs._list.splice.apply(obs._list,args);var extraRemoveListeners=args.slice(2).map(function(observ){return typeof observ==="function"?addListener(obs,observ):null});extraRemoveListeners.unshift(args[0],args[1]);var removedListeners=obs._removeListeners.splice.apply(obs._removeListeners,extraRemoveListeners);removedListeners.forEach(function(removeObservListener){if(removeObservListener){removeObservListener()}});return valueArgs}function unpack(value,index){if(index===0||index===1){return value}return typeof value==="function"?value():value}},{"./add-listener.js":1}],3:[function(require,module,exports){var ObservArray=require("./index.js");var slice=Array.prototype.slice;var ARRAY_METHODS=["concat","slice","every","filter","forEach","indexOf","join","lastIndexOf","map","reduce","reduceRight","some","toString","toLocaleString"];var methods=ARRAY_METHODS.map(function(name){return[name,function(){var res=this._list[name].apply(this._list,arguments);if(res&&Array.isArray(res)){res=ObservArray(res)}return res}]});module.exports=ArrayMethods;function ArrayMethods(obs){obs.push=observArrayPush;obs.pop=observArrayPop;obs.shift=observArrayShift;obs.unshift=observArrayUnshift;obs.reverse=require("./array-reverse.js");obs.sort=require("./array-sort.js");methods.forEach(function(tuple){obs[tuple[0]]=tuple[1]});return obs}function observArrayPush(){var args=slice.call(arguments);args.unshift(this._list.length,0);this.splice.apply(this,args);return this._list.length}function observArrayPop(){return this.splice(this._list.length-1,1)[0]}function observArrayShift(){return this.splice(0,1)[0]}function observArrayUnshift(){var args=slice.call(arguments);args.unshift(0,0);this.splice.apply(this,args);return this._list.length}function notImplemented(){throw new Error("Pull request welcome")}},{"./array-reverse.js":4,"./array-sort.js":5,"./index.js":undefined}],4:[function(require,module,exports){var applyPatch=require("./apply-patch.js");var setNonEnumerable=require("./lib/set-non-enumerable.js");module.exports=reverse;function reverse(){var obs=this;var changes=fakeDiff(obs._list.slice().reverse());var valueList=obs().slice().reverse();var valueChanges=changes.map(applyPatch.bind(obs,valueList));setNonEnumerable(valueList,"_diff",valueChanges);obs._observSet(valueList);return changes}function fakeDiff(arr){var _diff;var len=arr.length;if(len%2){var midPoint=(len-1)/2;var a=[0,midPoint].concat(arr.slice(0,midPoint));var b=[midPoint+1,midPoint].concat(arr.slice(midPoint+1,len));var _diff=[a,b]}else{_diff=[[0,len].concat(arr)]}return _diff}},{"./apply-patch.js":2,"./lib/set-non-enumerable.js":6}],5:[function(require,module,exports){var applyPatch=require("./apply-patch.js");var setNonEnumerable=require("./lib/set-non-enumerable.js");module.exports=sort;function sort(compare){var obs=this;var list=obs._list.slice();var unpacked=unpack(list);var sorted=unpacked.map(function(it){return it.val}).sort(compare);var packed=repack(sorted,unpacked);var changes=[[0,packed.length].concat(packed)];var valueChanges=changes.map(applyPatch.bind(obs,sorted));setNonEnumerable(sorted,"_diff",valueChanges);obs._observSet(sorted);return changes}function unpack(list){var unpacked=[];for(var i=0;i<list.length;i++){unpacked.push({val:"function"==typeof list[i]?list[i]():list[i],obj:list[i]})}return unpacked}function repack(sorted,unpacked){var packed=[];while(sorted.length){var s=sorted.shift();var indx=indexOf(s,unpacked);if(~indx)packed.push(unpacked.splice(indx,1)[0].obj)}return packed}function indexOf(n,h){for(var i=0;i<h.length;i++){if(n===h[i].val)return i}return-1}},{"./apply-patch.js":2,"./lib/set-non-enumerable.js":6}],6:[function(require,module,exports){module.exports=setNonEnumerable;function setNonEnumerable(object,key,value){Object.defineProperty(object,key,{value:value,writable:true,configurable:true,enumerable:false})}},{}],7:[function(require,module,exports){function head(a){return a[0]}function last(a){return a[a.length-1]}function tail(a){return a.slice(1)}function retreat(e){return e.pop()}function hasLength(e){return e.length}function any(ary,test){for(var i=0;i<ary.length;i++)if(test(ary[i]))return true;return false}function score(a){return a.reduce(function(s,a){return s+a.length+a[1]+1},0)}function best(a,b){return score(a)<=score(b)?a:b}var _rules;function _equal(a,b){if(a&&!b)return false;if(Array.isArray(a))if(a.length!=b.length)return false;if(a&&"object"==typeof a){for(var i in a)if(!_equal(a[i],b[i]))return false;for(var i in b)if(!_equal(a[i],b[i]))return false;return true}return a==b}function getArgs(args){return args.length==1?args[0]:[].slice.call(args)}function oddElement(ary,cmp){var c;function guess(a){var odd=-1;c=0;for(var i=a;i<ary.length;i++){if(!cmp(ary[a],ary[i])){odd=i,c++}}return c>1?-1:odd}var g=guess(0);if(-1!=g)return g;guess(1);return c==0?0:-1}var exports=module.exports=function(deps,exports){var equal=deps&&deps.equal||_equal;exports=exports||{};exports.lcs=function lcs(){var cache={};var args=getArgs(arguments);var a=args[0],b=args[1];function key(a,b){return a.length+":"+b.length}if(args.length>2){args.push(lcs(args.shift(),args.shift()));return lcs(args)}var start=0,end=0;for(var i=0;i<a.length&&i<b.length&&equal(a[i],b[i]);i++)start=i+1;if(a.length===start)return a.slice();for(var i=0;i<a.length-start&&i<b.length-start&&equal(a[a.length-1-i],b[b.length-1-i]);i++)end=i;function recurse(a,b){if(!a.length||!b.length)return[];if(cache[key(a,b)])return cache[key(a,b)];if(equal(a[0],b[0]))return[head(a)].concat(recurse(tail(a),tail(b)));else{var _a=recurse(tail(a),b);var _b=recurse(a,tail(b));return cache[key(a,b)]=_a.length>_b.length?_a:_b}}var middleA=a.slice(start,a.length-end);var middleB=b.slice(start,b.length-end);return a.slice(0,start).concat(recurse(middleA,middleB)).concat(a.slice(a.length-end))};exports.chunk=function(q,build){var q=q.map(function(e){return e.slice()});var lcs=exports.lcs.apply(null,q);var all=[lcs].concat(q);function matchLcs(e){if(e.length&&!lcs.length||!e.length&&lcs.length)return false;return equal(last(e),last(lcs))||e.length+lcs.length===0}while(any(q,hasLength)){while(q.every(matchLcs)&&q.every(hasLength))all.forEach(retreat);var c=false;var unstable=q.map(function(e){var change=[];while(!matchLcs(e)){change.unshift(retreat(e));c=true}return change});if(c)build(q[0].length,unstable)}};exports.optimisticDiff=function(a,b){var M=Math.max(a.length,b.length);var m=Math.min(a.length,b.length);var patch=[];for(var i=0;i<M;i++)if(a[i]!==b[i]){var cur=[i,0],deletes=0;while(a[i]!==b[i]&&i<m){cur[1]=++deletes;cur.push(b[i++])}if(i>=m){if(a.length>b.length)cur[1]+=a.length-b.length;else if(a.length<b.length)cur=cur.concat(b.slice(a.length))}patch.push(cur)}return patch};exports.diff=function(a,b){var optimistic=exports.optimisticDiff(a,b);var changes=[];exports.chunk([a,b],function(index,unstable){var del=unstable.shift().length;var insert=unstable.shift();changes.push([index,del].concat(insert))});return best(optimistic,changes)};exports.patch=function(a,changes,mutate){if(mutate!==true)a=a.slice(a);changes.forEach(function(change){[].splice.apply(a,change)});return a};exports.merge=function(){var args=getArgs(arguments);var patch=exports.diff3(args);return exports.patch(args[0],patch)};exports.diff3=function(){var args=getArgs(arguments);var r=[];exports.chunk(args,function(index,unstable){var mine=unstable[0];var insert=resolve(unstable);if(equal(mine,insert))return;r.push([index,mine.length].concat(insert))});return r};exports.oddOneOut=function oddOneOut(changes){changes=changes.slice();changes.unshift(changes.splice(1,1)[0]);var i=oddElement(changes,equal);if(i==0)return changes[1];if(~i)return changes[i]};exports.insertMergeOverDelete=function insertMergeOverDelete(changes){changes=changes.slice();changes.splice(1,1);for(var i=0,nonempty;i<changes.length;i++)if(changes[i].length)if(!nonempty)nonempty=changes[i];else return;return nonempty};var rules=deps&&deps.rules||[exports.oddOneOut,exports.insertMergeOverDelete];function resolve(changes){var l=rules.length;for(var i in rules){var c=rules[i]&&rules[i](changes);if(c)return c}changes.splice(1,1);return{"?":changes}}return exports};exports(null,exports)},{}],8:[function(require,module,exports){module.exports=Observable;function Observable(value){var listeners=[];value=value===undefined?null:value;observable.set=function(v){value=v;listeners.forEach(function(f){f(v)})};return observable;function observable(listener){if(!listener){return value}listeners.push(listener);return function remove(){listeners.splice(listeners.indexOf(listener),1)}}}},{}],9:[function(require,module,exports){var addListener=require("./add-listener.js");var setNonEnumerable=require("./lib/set-non-enumerable.js");module.exports=put;function put(index,value){var obs=this;var valueList=obs().slice();var originalLength=valueList.length;valueList[index]=typeof value==="function"?value():value;obs._list[index]=value;var removeListener=obs._removeListeners[index];if(removeListener){removeListener()}obs._removeListeners[index]=typeof value==="function"?addListener(obs,value):null;var valueArgs=index<originalLength?[index,1,valueList[index]]:[index,0,valueList[index]];setNonEnumerable(valueList,"_diff",[valueArgs]);obs._observSet(valueList);return value}},{"./add-listener.js":1,"./lib/set-non-enumerable.js":6}],10:[function(require,module,exports){var applyPatch=require("./apply-patch.js");var setNonEnumerable=require("./lib/set-non-enumerable.js");var adiff=require("adiff");module.exports=set;function set(rawList){if(!Array.isArray(rawList))rawList=[];var obs=this;var changes=adiff.diff(obs._list,rawList);var valueList=obs().slice();var valueChanges=changes.map(applyPatch.bind(obs,valueList));setNonEnumerable(valueList,"_diff",valueChanges);obs._observSet(valueList);return changes}},{"./apply-patch.js":2,"./lib/set-non-enumerable.js":6,adiff:7}],11:[function(require,module,exports){var slice=Array.prototype.slice;var addListener=require("./add-listener.js");var setNonEnumerable=require("./lib/set-non-enumerable.js");module.exports=splice;function splice(index,amount){var obs=this;var args=slice.call(arguments,0);var valueList=obs().slice();var valueArgs=args.map(function(value,index){if(index===0||index===1){return value}return typeof value==="function"?value():value});valueList.splice.apply(valueList,valueArgs);var removed=obs._list.splice.apply(obs._list,args);var extraRemoveListeners=args.slice(2).map(function(observ){return typeof observ==="function"?addListener(obs,observ):null});extraRemoveListeners.unshift(args[0],args[1]);var removedListeners=obs._removeListeners.splice.apply(obs._removeListeners,extraRemoveListeners);removedListeners.forEach(function(removeObservListener){if(removeObservListener){removeObservListener()}});setNonEnumerable(valueList,"_diff",[valueArgs]);obs._observSet(valueList);return removed}},{"./add-listener.js":1,"./lib/set-non-enumerable.js":6}],12:[function(require,module,exports){module.exports=transaction;function transaction(func){var obs=this;var rawList=obs._list.slice();if(func(rawList)!==false){return obs.set(rawList)}}},{}],"observ-array":[function(require,module,exports){var Observ=require("observ");module.exports=ObservArray;var splice=require("./splice.js");var put=require("./put.js");var set=require("./set.js");var transaction=require("./transaction.js");var ArrayMethods=require("./array-methods.js");var addListener=require("./add-listener.js");function ObservArray(initialList){var list=initialList;var initialState=[];list.forEach(function(observ,index){initialState[index]=typeof observ==="function"?observ():observ});var obs=Observ(initialState);obs.splice=splice;obs._observSet=obs.set;obs.set=set;obs.get=get;obs.getLength=getLength;obs.put=put;obs.transaction=transaction;obs._list=list;var removeListeners=list.map(function(observ){return typeof observ==="function"?addListener(obs,observ):null});obs._removeListeners=removeListeners;obs._type="observ-array";obs._version="3";return ArrayMethods(obs,list)}function get(index){return this._list[index]}function getLength(){return this._list.length}},{"./add-listener.js":1,"./array-methods.js":3,"./put.js":9,"./set.js":10,"./splice.js":11,"./transaction.js":12,observ:8}]},{},[]);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){module.exports=Observable;function Observable(value){var listeners=[];value=value===undefined?null:value;observable.set=function(v){value=v;listeners.forEach(function(f){f(v)})};return observable;function observable(listener){if(!listener){return value}listeners.push(listener);return function remove(){listeners.splice(listeners.indexOf(listener),1)}}}},{}],2:[function(require,module,exports){module.exports=extend;function extend(){var target={};for(var i=0;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(source.hasOwnProperty(key)){target[key]=source[key]}}}return target}},{}],"observ-struct":[function(require,module,exports){var Observ=require("observ");var extend=require("xtend");var blackList={length:"Clashes with `Function.prototype.length`.\n",name:"Clashes with `Function.prototype.name`.\n",_diff:"_diff is reserved key of observ-struct.\n",_type:"_type is reserved key of observ-struct.\n",_version:"_version is reserved key of observ-struct.\n"};var NO_TRANSACTION={};function setNonEnumerable(object,key,value){Object.defineProperty(object,key,{value:value,writable:true,configurable:true,enumerable:false})}module.exports=ObservStruct;function ObservStruct(struct){var keys=Object.keys(struct);var initialState={};var currentTransaction=NO_TRANSACTION;var nestedTransaction=NO_TRANSACTION;keys.forEach(function(key){if(blackList.hasOwnProperty(key)){throw new Error("cannot create an observ-struct "+"with a key named '"+key+"'.\n"+blackList[key])}var observ=struct[key];initialState[key]=typeof observ==="function"?observ():observ});var obs=Observ(initialState);keys.forEach(function(key){var observ=struct[key];obs[key]=observ;if(typeof observ==="function"){observ(function(value){if(nestedTransaction===value){return}var state=extend(obs());state[key]=value;var diff={};diff[key]=value&&value._diff?value._diff:value;setNonEnumerable(state,"_diff",diff);currentTransaction=state;obs.set(state);currentTransaction=NO_TRANSACTION})}});var _set=obs.set;obs.set=function trackDiff(value){if(currentTransaction===value){return _set(value)}var newState=extend(value);setNonEnumerable(newState,"_diff",value);_set(newState)};obs(function(newState){if(currentTransaction===newState){return}keys.forEach(function(key){var observ=struct[key];var newObservValue=newState[key];if(typeof observ==="function"&&observ()!==newObservValue){nestedTransaction=newObservValue;observ.set(newState[key]);nestedTransaction=NO_TRANSACTION}})});obs._type="observ-struct";obs._version="5";return obs}},{observ:1,xtend: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){module.exports=Observable;function Observable(value){var listeners=[];value=value===undefined?null:value;observable.set=function(v){value=v;listeners.forEach(function(f){f(v)})};return observable;function observable(listener){if(!listener){return value}listeners.push(listener);return function remove(){listeners.splice(listeners.indexOf(listener),1)}}}},{}],"observ/computed":[function(require,module,exports){var Observable=require("./index.js");module.exports=computed;function computed(observables,lambda){var values=observables.map(function(o){return o()});var result=Observable(lambda.apply(null,values));observables.forEach(function(o,index){o(function(newValue){values[index]=newValue;result.set(lambda.apply(null,values))})});return result}},{"./index.js":1}]},{},[]);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 createElement=require("./vdom/create-element.js");module.exports=createElement},{"./vdom/create-element.js":14}],3:[function(require,module,exports){var diff=require("./vtree/diff.js");module.exports=diff},{"./vtree/diff.js":34}],4:[function(require,module,exports){var h=require("./virtual-hyperscript/index.js");module.exports=h},{"./virtual-hyperscript/index.js":21}],5:[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}()},{}],6:[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":8}],7:[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:{})},{}],8:[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":7}],9:[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}],10:[function(require,module,exports){"use strict";module.exports=function isObject(x){return typeof x==="object"&&x!==null}},{}],11:[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]"}},{}],12:[function(require,module,exports){var patch=require("./vdom/patch.js");module.exports=patch},{"./vdom/patch.js":17}],13:[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,propName,propValue,previous)}else if(isHook(propValue)){removeProperty(node,propName,propValue,previous);if(propValue.hook){propValue.hook(node,propName,previous?previous[propName]:undefined)}}else{if(isObject(propValue)){patchObject(node,props,previous,propName,propValue)}else{node[propName]=propValue}}}}function removeProperty(node,propName,propValue,previous){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,propValue)}}}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":25,"is-object":10}],14:[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":23,"../vnode/is-vnode.js":26,"../vnode/is-vtext.js":27,"../vnode/is-widget.js":28,"./apply-properties":13,"global/document":9}],15:[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}},{}],16:[function(require,module,exports){var applyProperties=require("./apply-properties");var isWidget=require("../vnode/is-widget.js");var VPatch=require("../vnode/vpatch.js");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=renderOptions.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=renderOptions.render(vText,renderOptions);if(parentNode&&newNode!==domNode){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=renderOptions.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=renderOptions.render(vNode,renderOptions);if(parentNode&&newNode!==domNode){parentNode.replaceChild(newNode,domNode)}return newNode}function destroyWidget(domNode,w){if(typeof w.destroy==="function"&&isWidget(w)){w.destroy(domNode)}}function reorderChildren(domNode,moves){var childNodes=domNode.childNodes;var keyMap={};var node;var remove;var insert;for(var i=0;i<moves.removes.length;i++){remove=moves.removes[i];node=childNodes[remove.from];if(remove.key){keyMap[remove.key]=node}domNode.removeChild(node)}var length=childNodes.length;for(var j=0;j<moves.inserts.length;j++){insert=moves.inserts[j];node=keyMap[insert.key];domNode.insertBefore(node,insert.to>=length++?null:childNodes[insert.to])}}function replaceRoot(oldRoot,newRoot){if(oldRoot&&newRoot&&oldRoot!==newRoot&&oldRoot.parentNode){oldRoot.parentNode.replaceChild(newRoot,oldRoot)}return newRoot}},{"../vnode/is-widget.js":28,"../vnode/vpatch.js":31,"./apply-properties":13,"./update-widget":18}],17:[function(require,module,exports){var document=require("global/document");var isArray=require("x-is-array");var render=require("./create-element");var domIndex=require("./dom-index");var patchOp=require("./patch-op");module.exports=patch;function patch(rootNode,patches,renderOptions){renderOptions=renderOptions||{};renderOptions.patch=renderOptions.patch&&renderOptions.patch!==patch?renderOptions.patch:patchRecursive;renderOptions.render=renderOptions.render||render;return renderOptions.patch(rootNode,patches,renderOptions)}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.document&&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}},{"./create-element":14,"./dom-index":15,"./patch-op":16,"global/document":9,"x-is-array":11}],18:[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":28}],19:[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":6}],20:[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}}},{}],21:[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(typeof c==="number"){childNodes.push(new VText(String(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":24,"../vnode/is-vhook":25,"../vnode/is-vnode":26,"../vnode/is-vtext":27,"../vnode/is-widget":28,"../vnode/vnode.js":30,"../vnode/vtext.js":32,"./hooks/ev-hook.js":19,"./hooks/soft-set-hook.js":20,"./parse-tag.js":22,"x-is-array":11}],22:[function(require,module,exports){"use strict";var split=require("browser-split");var classIdSplit=/([\.#]?[a-zA-Z0-9\u007F-\uFFFF_:-]+)/;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":5}],23:[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":24,"./is-vnode":26,"./is-vtext":27,"./is-widget":28}],24:[function(require,module,exports){module.exports=isThunk;function isThunk(t){return t&&t.type==="Thunk"}},{}],25:[function(require,module,exports){module.exports=isHook;function isHook(hook){return hook&&(typeof hook.hook==="function"&&!hook.hasOwnProperty("hook")||typeof hook.unhook==="function"&&!hook.hasOwnProperty("unhook"))}},{}],26:[function(require,module,exports){var version=require("./version");module.exports=isVirtualNode;function isVirtualNode(x){return x&&x.type==="VirtualNode"&&x.version===version}},{"./version":29}],27:[function(require,module,exports){var version=require("./version");module.exports=isVirtualText;function isVirtualText(x){return x&&x.type==="VirtualText"&&x.version===version}},{"./version":29}],28:[function(require,module,exports){module.exports=isWidget;function isWidget(w){return w&&w.type==="Widget"}},{}],29:[function(require,module,exports){module.exports="2"},{}],30:[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":24,"./is-vhook":25,"./is-vnode":26,"./is-widget":28,"./version":29}],31:[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":29}],32:[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":29}],33:[function(require,module,exports){var isObject=require("is-object");var isHook=require("../vnode/is-vhook");module.exports=diffProps;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}}},{"../vnode/is-vhook":25,"is-object":10}],34:[function(require,module,exports){var isArray=require("x-is-array");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 handleThunk=require("../vnode/handle-thunk");var diffProps=require("./diff-props");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 diffChildren(a,b,patch,apply,index){var aChildren=a.children;var orderedSet=reorder(aChildren,b.children);var bChildren=orderedSet.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(orderedSet.moves){apply=appendPatch(apply,new VPatch(VPatch.ORDER,a,orderedSet.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 bChildIndex=keyIndex(bChildren);var bKeys=bChildIndex.keys;var bFree=bChildIndex.free;if(bFree.length===bChildren.length){return{children:bChildren,moves:null}}var aChildIndex=keyIndex(aChildren);var aKeys=aChildIndex.keys;var aFree=aChildIndex.free;if(aFree.length===aChildren.length){return{children:bChildren,moves:null}}var newChildren=[];var freeIndex=0;var freeCount=bFree.length;var deletedItems=0;for(var i=0;i<aChildren.length;i++){var aItem=aChildren[i];var itemIndex;if(aItem.key){if(bKeys.hasOwnProperty(aItem.key)){itemIndex=bKeys[aItem.key];newChildren.push(bChildren[itemIndex])}else{itemIndex=i-deletedItems++;newChildren.push(null)}}else{if(freeIndex<freeCount){itemIndex=bFree[freeIndex++];newChildren.push(bChildren[itemIndex])}else{itemIndex=i-deletedItems++;newChildren.push(null)}}}var lastFreeIndex=freeIndex>=bFree.length?bChildren.length:bFree[freeIndex];for(var j=0;j<bChildren.length;j++){var newItem=bChildren[j];if(newItem.key){if(!aKeys.hasOwnProperty(newItem.key)){newChildren.push(newItem)}}else if(j>=lastFreeIndex){newChildren.push(newItem)}}var simulate=newChildren.slice();var simulateIndex=0;var removes=[];var inserts=[];var simulateItem;for(var k=0;k<bChildren.length;){var wantedItem=bChildren[k];simulateItem=simulate[simulateIndex];while(simulateItem===null&&simulate.length){removes.push(remove(simulate,simulateIndex,null));simulateItem=simulate[simulateIndex]}if(!simulateItem||simulateItem.key!==wantedItem.key){if(wantedItem.key){if(simulateItem&&simulateItem.key){if(bKeys[simulateItem.key]!==k+1){removes.push(remove(simulate,simulateIndex,simulateItem.key));simulateItem=simulate[simulateIndex];if(!simulateItem||simulateItem.key!==wantedItem.key){inserts.push({key:wantedItem.key,to:k})}else{simulateIndex++}}else{inserts.push({key:wantedItem.key,to:k})}}else{inserts.push({key:wantedItem.key,to:k})}k++}else if(simulateItem&&simulateItem.key){removes.push(remove(simulate,simulateIndex,simulateItem.key))}}else{simulateIndex++;k++}}while(simulateIndex<simulate.length){simulateItem=simulate[simulateIndex];removes.push(remove(simulate,simulateIndex,simulateItem&&simulateItem.key))}if(removes.length===deletedItems&&!inserts.length){return{children:newChildren,moves:null}}return{children:newChildren,moves:{removes:removes,inserts:inserts}}}function remove(arr,index,key){arr.splice(index,1);return{from:index,key:key}}function keyIndex(children){var keys={};var free=[];var length=children.length;for(var i=0;i<length;i++){var child=children[i];if(child.key){keys[child.key]=i}else{free.push(i)}}return{keys:keys,free:free}}function appendPatch(apply,patch){if(apply){if(isArray(apply)){apply.push(patch)}else{apply=[apply,patch]}return apply}else{return patch}}},{"../vnode/handle-thunk":23,"../vnode/is-thunk":24,"../vnode/is-vnode":26,"../vnode/is-vtext":27,"../vnode/is-widget":28,"../vnode/vpatch":31,"./diff-props":33,"x-is-array":11}],"virtual-dom":[function(require,module,exports){var diff=require("./diff.js");var patch=require("./patch.js");var h=require("./h.js");var create=require("./create-element.js");var VNode=require("./vnode/vnode.js");var VText=require("./vnode/vtext.js");module.exports={diff:diff,patch:patch,h:h,create:create,VNode:VNode,VText:VText}},{"./create-element.js":2,"./diff.js":3,"./h.js":4,"./patch.js":12,"./vnode/vnode.js":30,"./vnode/vtext.js":32}]},{},[]);var ObservStruct=require("observ-struct"),ObservArray=require("observ-array"),Computed=require("observ/computed"),vdom=require("virtual-dom"),h=vdom.h;var state=ObservStruct({users:ObservArray([ObservStruct({id:0,name:"foo"}),ObservStruct({id:1,name:"bar"})])});var hooks={user:ObserveArray([])};function renderableApp(){return Computed([renderableUsers()],function(users){return h("div.app",[h("h1","A list of users"),users])})}function renderableUsers(){return Computed([state.users.map(renderableUser)],function(users){return h("div.user-list",[users])})}function renderableUser(user){return Computed([user,hooks.user],function(user,hook){return h("div.user",[user.name].concat(hook))})}var app=renderableApp(),tree=app(),rootNode=vdom.create(tree);document.body.appendChild(rootNode);app(function(newTree){var patches=vdom.diff(tree,newTree);vdom.patch(rootNode,patches);tree=newTree}); |
This file contains hidden or 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": { | |
"observ-array": "3.2.1", | |
"observ-struct": "6.0.0", | |
"observ": "0.2.0", | |
"virtual-dom": "2.1.1" | |
} | |
} |
This file contains hidden or 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
<!-- contents of this file will be placed inside the <body> --> |
This file contains hidden or 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
<!-- 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