Comparing version 0.0.14 to 0.0.15
69
app.js
@@ -9,8 +9,8 @@ var patch = require("snabbdom").init([ | ||
module.exports = function app(options) { | ||
module.exports = function app (options) { | ||
var model = options.model, | ||
view = options.view, | ||
reducers = options.reducers || options.update || {}, | ||
subs = options.subscriptions || {}, | ||
reducers = options.update || {}, | ||
effects = options.effects || {}, | ||
subs = options.subs || {}, | ||
hooks = options.hooks || {}, | ||
@@ -21,24 +21,20 @@ root = options.root || document.body.appendChild(document.createElement("div")) | ||
var reduce = reducers[name] | ||
if (typeof reduce !== "function") { | ||
throw TypeError(name + " is not a reducer or effect") | ||
} | ||
return reduce(model, data) | ||
} | ||
Object | ||
.keys(reducers) | ||
.concat(Object.keys(effects)) | ||
.forEach(function (name) { | ||
if (reducers[name] !== undefined && effects[name] !== undefined) { | ||
throw TypeError(name + " is already defined as a reducer or effect") | ||
} | ||
dispatch[name] = function (data) { | ||
dispatch(name, data) | ||
} | ||
}) | ||
for (var name in reducers) { | ||
wrap(dispatch, name) | ||
} | ||
for (var name in effects) { | ||
if (dispatch[name] !== undefined) { | ||
throw TypeError(name + " is already defined as a reducer or effect") | ||
} | ||
wrap(dispatch, name) | ||
} | ||
document.addEventListener("DOMContentLoaded", function () { | ||
Object.keys(subs).forEach(function (key) { | ||
for (var key in subs) { | ||
subs[key](model, dispatch, error) | ||
}) | ||
} | ||
}) | ||
@@ -48,10 +44,9 @@ | ||
function render(model, view, update, lastNode) { | ||
if (view === undefined) { | ||
return | ||
function render (model, view, update, lastNode) { | ||
if (view !== undefined) { | ||
patch(lastNode, root = view(model, dispatch)) | ||
} | ||
patch(lastNode, root = view(model, dispatch)) | ||
} | ||
function error(err) { | ||
function error (err) { | ||
if (hooks.onError === undefined) { | ||
@@ -63,7 +58,9 @@ throw err | ||
function dispatch(name, data) { | ||
function dispatch (name, data) { | ||
if (hooks.onAction !== undefined) { | ||
hooks.onAction(name, data) | ||
} | ||
var effect = effects[name] | ||
if (typeof effect === "function") { | ||
@@ -73,3 +70,5 @@ effect(model, dispatch, error) | ||
var lastModel = model | ||
render(model = update(model, name, data), view, update, root) | ||
render(model = merge(model, update(model, name, data)), view, update, root) | ||
if (hooks.onUpdate !== undefined) { | ||
@@ -80,2 +79,20 @@ hooks.onUpdate(lastModel, model, data) | ||
} | ||
function merge (target, source) { | ||
if (typeof source === "string") { | ||
return source | ||
} | ||
for (var key in source) { | ||
target[key] = source[key] | ||
} | ||
return key === undefined ? source : target | ||
} | ||
function wrap (func, key) { | ||
func[key] = function (data) { | ||
func(key, data) | ||
} | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.app=f()}})(function(){var define,module,exports;return 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 patch=require("snabbdom").init([require("snabbdom/modules/class"),require("snabbdom/modules/props"),require("snabbdom/modules/style"),require("snabbdom/modules/attributes"),require("snabbdom/modules/eventlisteners")]);module.exports=function(e){function o(e,o,n,t){void 0!==o&&patch(t,a=o(e,r))}function n(e){if(void 0===u.onError)throw e;u.onError(e)}function r(e,d){void 0!==u.onAction&&u.onAction(e,d);var c=s[e];if("function"==typeof c)c(t,r,n);else{var b=t;o(t=f(t,e,d),i,f,a),void 0!==u.onUpdate&&u.onUpdate(b,t,d)}}var t=e.model,i=e.view,d=e.reducers||e.update||{},c=e.subscriptions||{},s=e.effects||{},u=e.hooks||{},a=e.root||document.body.appendChild(document.createElement("div")),f=function(e,o,n){var r=d[o];if("function"!=typeof r)throw TypeError(o+" is not a reducer or effect");return r(e,n)};Object.keys(d).concat(Object.keys(s)).forEach(function(e){if(void 0!==d[e]&&void 0!==s[e])throw TypeError(e+" is already defined as a reducer or effect");r[e]=function(o){r(e,o)}}),document.addEventListener("DOMContentLoaded",function(){Object.keys(c).forEach(function(e){c[e](t,r,n)})}),o(t,i,f,a)}},{snabbdom:9,"snabbdom/modules/attributes":4,"snabbdom/modules/class":5,"snabbdom/modules/eventlisteners":6,"snabbdom/modules/props":7,"snabbdom/modules/style":8}],2:[function(require,module,exports){function createElement(e){return document.createElement(e)}function createElementNS(e,t){return document.createElementNS(e,t)}function createTextNode(e){return document.createTextNode(e)}function insertBefore(e,t,n){e.insertBefore(t,n)}function removeChild(e,t){e.removeChild(t)}function appendChild(e,t){e.appendChild(t)}function parentNode(e){return e.parentElement}function nextSibling(e){return e.nextSibling}function tagName(e){return e.tagName}function setTextContent(e,t){e.textContent=t}module.exports={createElement:createElement,createElementNS:createElementNS,createTextNode:createTextNode,appendChild:appendChild,removeChild:removeChild,insertBefore:insertBefore,parentNode:parentNode,nextSibling:nextSibling,tagName:tagName,setTextContent:setTextContent}},{}],3:[function(require,module,exports){module.exports={array:Array.isArray,primitive:function(r){return"string"==typeof r||"number"==typeof r}}},{}],4:[function(require,module,exports){function updateAttrs(e,t){var a,r,l,s,o=t.elm,n=e.data.attrs,d=t.data.attrs;if(n||d){n=n||{},d=d||{};for(a in d)r=d[a],l=n[a],l!==r&&(!r&&booleanAttrsDict[a]?o.removeAttribute(a):(s=a.split(":"),s.length>1&&NamespaceURIs.hasOwnProperty(s[0])?o.setAttributeNS(NamespaceURIs[s[0]],a,r):o.setAttribute(a,r)));for(a in n)a in d||o.removeAttribute(a)}}for(var NamespaceURIs={xlink:"http://www.w3.org/1999/xlink"},booleanAttrs=["allowfullscreen","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","draggable","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","spellcheck","translate","truespeed","typemustmatch","visible"],booleanAttrsDict=Object.create(null),i=0,len=booleanAttrs.length;i<len;i++)booleanAttrsDict[booleanAttrs[i]]=!0;module.exports={create:updateAttrs,update:updateAttrs}},{}],5:[function(require,module,exports){function updateClass(a,s){var e,t,d=s.elm,l=a.data.class,o=s.data.class;if(l||o){l=l||{},o=o||{};for(t in l)o[t]||d.classList.remove(t);for(t in o)e=o[t],e!==l[t]&&d.classList[e?"add":"remove"](t)}}module.exports={create:updateClass,update:updateClass}},{}],6:[function(require,module,exports){function invokeHandler(e,n,t){if("function"==typeof e)e.call(n,t,n);else if("object"==typeof e)if("function"==typeof e[0])if(2===e.length)e[0].call(n,e[1],t,n);else{var i=e.slice(1);i.push(t),i.push(n),e[0].apply(n,i)}else for(var r=0;r<e.length;r++)invokeHandler(e[r])}function handleEvent(e,n){var t=e.type,i=n.data.on;i&&i[t]&&invokeHandler(i[t],n,e)}function createListener(){return function e(n){handleEvent(n,e.vnode)}}function updateEventListeners(e,n){var t,i=e.data.on,r=e.listener,a=e.elm,o=n&&n.data.on,s=n&&n.elm;if(i!==o){if(i&&r)if(o)for(t in i)o[t]||a.removeEventListener(t,r,!1);else for(t in i)a.removeEventListener(t,r,!1);if(o){var f=n.listener=e.listener||createListener();if(f.vnode=n,i)for(t in o)i[t]||s.addEventListener(t,f,!1);else for(t in o)s.addEventListener(t,f,!1)}}}module.exports={create:updateEventListeners,update:updateEventListeners,destroy:updateEventListeners}},{}],7:[function(require,module,exports){function updateProps(e,p){var a,o,r,t=p.elm,d=e.data.props,u=p.data.props;if(d||u){d=d||{},u=u||{};for(a in d)u[a]||delete t[a];for(a in u)o=u[a],r=d[a],r===o||"value"===a&&t[a]===o||(t[a]=o)}}module.exports={create:updateProps,update:updateProps}},{}],8:[function(require,module,exports){function setNextFrame(e,t,a){nextFrame(function(){e[t]=a})}function updateStyle(e,t){var a,n,r=t.elm,o=e.data.style,l=t.data.style;if(o||l){o=o||{},l=l||{};var i="delayed"in o;for(n in o)l[n]||(r.style[n]="");for(n in l)if(a=l[n],"delayed"===n)for(n in l.delayed)a=l.delayed[n],i&&a===o.delayed[n]||setNextFrame(r.style,n,a);else"remove"!==n&&a!==o[n]&&(r.style[n]=a)}}function applyDestroyStyle(e){var t,a,n=e.elm,r=e.data.style;if(r&&(t=r.destroy))for(a in t)n.style[a]=t[a]}function applyRemoveStyle(e,t){var a=e.data.style;if(!a||!a.remove)return void t();var n,r,o=e.elm,l=0,i=a.remove,y=0,d=[];for(n in i)d.push(n),o.style[n]=i[n];r=getComputedStyle(o);for(var f=r["transition-property"].split(", ");l<f.length;++l)d.indexOf(f[l])!==-1&&y++;o.addEventListener("transitionend",function(e){e.target===o&&--y,0===y&&t()})}var raf="undefined"!=typeof window&&window.requestAnimationFrame||setTimeout,nextFrame=function(e){raf(function(){raf(e)})};module.exports={create:updateStyle,update:updateStyle,destroy:applyDestroyStyle,remove:applyRemoveStyle}},{}],9:[function(require,module,exports){"use strict";function isUndef(e){return void 0===e}function isDef(e){return void 0!==e}function sameVnode(e,t){return e.key===t.key&&e.sel===t.sel}function createKeyToOldIdx(e,t,i){var n,o,r={};for(n=t;n<=i;++n)o=e[n].key,isDef(o)&&(r[o]=n);return r}function init(e,t){function i(e){var i=e.id?"#"+e.id:"",n=e.className?"."+e.className.split(" ").join("."):"";return VNode(t.tagName(e).toLowerCase()+i+n,{},[],void 0,e)}function n(e,i){return function(){if(0===--i){var n=t.parentNode(e);t.removeChild(n,e)}}}function o(e,i){var n,r=e.data;isDef(r)&&isDef(n=r.hook)&&isDef(n=n.init)&&(n(e),r=e.data);var s,f=e.children,d=e.sel;if(isDef(d)){var l=d.indexOf("#"),a=d.indexOf(".",l),m=l>0?l:d.length,c=a>0?a:d.length,u=l!==-1||a!==-1?d.slice(0,Math.min(m,c)):d;if(s=e.elm=isDef(r)&&isDef(n=r.ns)?t.createElementNS(n,u):t.createElement(u),m<c&&(s.id=d.slice(m+1,c)),a>0&&(s.className=d.slice(c+1).replace(/\./g," ")),is.array(f))for(n=0;n<f.length;++n)t.appendChild(s,o(f[n],i));else is.primitive(e.text)&&t.appendChild(s,t.createTextNode(e.text));for(n=0;n<h.create.length;++n)h.create[n](emptyNode,e);n=e.data.hook,isDef(n)&&(n.create&&n.create(emptyNode,e),n.insert&&i.push(e))}else s=e.elm=t.createTextNode(e.text);return e.elm}function r(e,i,n,r,s,f){for(;r<=s;++r)t.insertBefore(e,o(n[r],f),i)}function s(e){var t,i,n=e.data;if(isDef(n)){for(isDef(t=n.hook)&&isDef(t=t.destroy)&&t(e),t=0;t<h.destroy.length;++t)h.destroy[t](e);if(isDef(t=e.children))for(i=0;i<e.children.length;++i)s(e.children[i])}}function f(e,i,o,r){for(;o<=r;++o){var f,d,l,a=i[o];if(isDef(a))if(isDef(a.sel)){for(s(a),d=h.remove.length+1,l=n(a.elm,d),f=0;f<h.remove.length;++f)h.remove[f](a,l);isDef(f=a.data)&&isDef(f=f.hook)&&isDef(f=f.remove)?f(a,l):l()}else t.removeChild(e,a.elm)}}function d(e,i,n,s){for(var d,a,m,h,c=0,u=0,p=i.length-1,v=i[0],D=i[p],g=n.length-1,x=n[0],k=n[g];c<=p&&u<=g;)isUndef(v)?v=i[++c]:isUndef(D)?D=i[--p]:sameVnode(v,x)?(l(v,x,s),v=i[++c],x=n[++u]):sameVnode(D,k)?(l(D,k,s),D=i[--p],k=n[--g]):sameVnode(v,k)?(l(v,k,s),t.insertBefore(e,v.elm,t.nextSibling(D.elm)),v=i[++c],k=n[--g]):sameVnode(D,x)?(l(D,x,s),t.insertBefore(e,D.elm,v.elm),D=i[--p],x=n[++u]):(isUndef(d)&&(d=createKeyToOldIdx(i,c,p)),a=d[x.key],isUndef(a)?(t.insertBefore(e,o(x,s),v.elm),x=n[++u]):(m=i[a],l(m,x,s),i[a]=void 0,t.insertBefore(e,m.elm,v.elm),x=n[++u]));c>p?(h=isUndef(n[g+1])?null:n[g+1].elm,r(e,h,n,u,g,s)):u>g&&f(e,i,c,p)}function l(e,i,n){var s,l;isDef(s=i.data)&&isDef(l=s.hook)&&isDef(s=l.prepatch)&&s(e,i);var a=i.elm=e.elm,m=e.children,c=i.children;if(e!==i){if(!sameVnode(e,i)){var u=t.parentNode(e.elm);return a=o(i,n),t.insertBefore(u,a,e.elm),void f(u,[e],0,0)}if(isDef(i.data)){for(s=0;s<h.update.length;++s)h.update[s](e,i);s=i.data.hook,isDef(s)&&isDef(s=s.update)&&s(e,i)}isUndef(i.text)?isDef(m)&&isDef(c)?m!==c&&d(a,m,c,n):isDef(c)?(isDef(e.text)&&t.setTextContent(a,""),r(a,null,c,0,c.length-1,n)):isDef(m)?f(a,m,0,m.length-1):isDef(e.text)&&t.setTextContent(a,""):e.text!==i.text&&t.setTextContent(a,i.text),isDef(l)&&isDef(s=l.postpatch)&&s(e,i)}}var a,m,h={};for(isUndef(t)&&(t=domApi),a=0;a<hooks.length;++a)for(h[hooks[a]]=[],m=0;m<e.length;++m)void 0!==e[m][hooks[a]]&&h[hooks[a]].push(e[m][hooks[a]]);return function(e,n){var r,s,d,a=[];for(r=0;r<h.pre.length;++r)h.pre[r]();for(isUndef(e.sel)&&(e=i(e)),sameVnode(e,n)?l(e,n,a):(s=e.elm,d=t.parentNode(s),o(n,a),null!==d&&(t.insertBefore(d,n.elm,t.nextSibling(s)),f(d,[e],0,0))),r=0;r<a.length;++r)a[r].data.hook.insert(a[r]);for(r=0;r<h.post.length;++r)h.post[r]();return n}}var VNode=require("./vnode"),is=require("./is"),domApi=require("./htmldomapi"),emptyNode=VNode("",{},[],void 0,void 0),hooks=["create","update","remove","destroy","pre","post"];module.exports={init:init}},{"./htmldomapi":2,"./is":3,"./vnode":10}],10:[function(require,module,exports){module.exports=function(e,t,d,o,r){var i=void 0===t?void 0:t.key;return{sel:e,data:t,children:d,text:o,elm:r,key:i}}},{}]},{},[1])(1)}); | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.app=f()}})(function(){var define,module,exports;return 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 patch=require("snabbdom").init([require("snabbdom/modules/class"),require("snabbdom/modules/props"),require("snabbdom/modules/style"),require("snabbdom/modules/attributes"),require("snabbdom/modules/eventlisteners")]);module.exports=function(o){function e(o,e,n,t){void 0!==e&&patch(t,v=e(o,r))}function n(o){if(void 0===c.onError)throw o;c.onError(o)}function r(o,i){void 0!==c.onAction&&c.onAction(o,i);var a=s[o];if("function"==typeof a)a(d,r,n);else{var f=d;e(d=t(d,m(d,o,i)),u,m,v),void 0!==c.onUpdate&&c.onUpdate(f,d,i)}}function t(o,e){if("string"==typeof e)return e;for(var n in e)o[n]=e[n];return void 0===n?e:o}function i(o,e){o[e]=function(n){o(e,n)}}var d=o.model,u=o.view,a=o.update||{},s=o.effects||{},f=o.subs||{},c=o.hooks||{},v=o.root||document.body.appendChild(document.createElement("div")),m=function(o,e,n){var r=a[e];return r(o,n)};for(var b in a)i(r,b);for(var b in s){if(void 0!==r[b])throw TypeError(b+" is already defined as a reducer or effect");i(r,b)}document.addEventListener("DOMContentLoaded",function(){for(var o in f)f[o](d,r,n)}),e(d,u,m,v)}},{snabbdom:9,"snabbdom/modules/attributes":4,"snabbdom/modules/class":5,"snabbdom/modules/eventlisteners":6,"snabbdom/modules/props":7,"snabbdom/modules/style":8}],2:[function(require,module,exports){function createElement(e){return document.createElement(e)}function createElementNS(e,t){return document.createElementNS(e,t)}function createTextNode(e){return document.createTextNode(e)}function insertBefore(e,t,n){e.insertBefore(t,n)}function removeChild(e,t){e.removeChild(t)}function appendChild(e,t){e.appendChild(t)}function parentNode(e){return e.parentElement}function nextSibling(e){return e.nextSibling}function tagName(e){return e.tagName}function setTextContent(e,t){e.textContent=t}module.exports={createElement:createElement,createElementNS:createElementNS,createTextNode:createTextNode,appendChild:appendChild,removeChild:removeChild,insertBefore:insertBefore,parentNode:parentNode,nextSibling:nextSibling,tagName:tagName,setTextContent:setTextContent}},{}],3:[function(require,module,exports){module.exports={array:Array.isArray,primitive:function(r){return"string"==typeof r||"number"==typeof r}}},{}],4:[function(require,module,exports){function updateAttrs(e,t){var a,r,l,s,o=t.elm,n=e.data.attrs,d=t.data.attrs;if(n||d){n=n||{},d=d||{};for(a in d)r=d[a],l=n[a],l!==r&&(!r&&booleanAttrsDict[a]?o.removeAttribute(a):(s=a.split(":"),s.length>1&&NamespaceURIs.hasOwnProperty(s[0])?o.setAttributeNS(NamespaceURIs[s[0]],a,r):o.setAttribute(a,r)));for(a in n)a in d||o.removeAttribute(a)}}for(var NamespaceURIs={xlink:"http://www.w3.org/1999/xlink"},booleanAttrs=["allowfullscreen","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","draggable","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","spellcheck","translate","truespeed","typemustmatch","visible"],booleanAttrsDict=Object.create(null),i=0,len=booleanAttrs.length;i<len;i++)booleanAttrsDict[booleanAttrs[i]]=!0;module.exports={create:updateAttrs,update:updateAttrs}},{}],5:[function(require,module,exports){function updateClass(a,s){var e,t,d=s.elm,l=a.data.class,o=s.data.class;if(l||o){l=l||{},o=o||{};for(t in l)o[t]||d.classList.remove(t);for(t in o)e=o[t],e!==l[t]&&d.classList[e?"add":"remove"](t)}}module.exports={create:updateClass,update:updateClass}},{}],6:[function(require,module,exports){function invokeHandler(e,n,t){if("function"==typeof e)e.call(n,t,n);else if("object"==typeof e)if("function"==typeof e[0])if(2===e.length)e[0].call(n,e[1],t,n);else{var i=e.slice(1);i.push(t),i.push(n),e[0].apply(n,i)}else for(var r=0;r<e.length;r++)invokeHandler(e[r])}function handleEvent(e,n){var t=e.type,i=n.data.on;i&&i[t]&&invokeHandler(i[t],n,e)}function createListener(){return function e(n){handleEvent(n,e.vnode)}}function updateEventListeners(e,n){var t,i=e.data.on,r=e.listener,a=e.elm,o=n&&n.data.on,s=n&&n.elm;if(i!==o){if(i&&r)if(o)for(t in i)o[t]||a.removeEventListener(t,r,!1);else for(t in i)a.removeEventListener(t,r,!1);if(o){var f=n.listener=e.listener||createListener();if(f.vnode=n,i)for(t in o)i[t]||s.addEventListener(t,f,!1);else for(t in o)s.addEventListener(t,f,!1)}}}module.exports={create:updateEventListeners,update:updateEventListeners,destroy:updateEventListeners}},{}],7:[function(require,module,exports){function updateProps(e,p){var a,o,r,t=p.elm,d=e.data.props,u=p.data.props;if(d||u){d=d||{},u=u||{};for(a in d)u[a]||delete t[a];for(a in u)o=u[a],r=d[a],r===o||"value"===a&&t[a]===o||(t[a]=o)}}module.exports={create:updateProps,update:updateProps}},{}],8:[function(require,module,exports){function setNextFrame(e,t,a){nextFrame(function(){e[t]=a})}function updateStyle(e,t){var a,n,r=t.elm,o=e.data.style,l=t.data.style;if(o||l){o=o||{},l=l||{};var i="delayed"in o;for(n in o)l[n]||(r.style[n]="");for(n in l)if(a=l[n],"delayed"===n)for(n in l.delayed)a=l.delayed[n],i&&a===o.delayed[n]||setNextFrame(r.style,n,a);else"remove"!==n&&a!==o[n]&&(r.style[n]=a)}}function applyDestroyStyle(e){var t,a,n=e.elm,r=e.data.style;if(r&&(t=r.destroy))for(a in t)n.style[a]=t[a]}function applyRemoveStyle(e,t){var a=e.data.style;if(!a||!a.remove)return void t();var n,r,o=e.elm,l=0,i=a.remove,y=0,d=[];for(n in i)d.push(n),o.style[n]=i[n];r=getComputedStyle(o);for(var f=r["transition-property"].split(", ");l<f.length;++l)d.indexOf(f[l])!==-1&&y++;o.addEventListener("transitionend",function(e){e.target===o&&--y,0===y&&t()})}var raf="undefined"!=typeof window&&window.requestAnimationFrame||setTimeout,nextFrame=function(e){raf(function(){raf(e)})};module.exports={create:updateStyle,update:updateStyle,destroy:applyDestroyStyle,remove:applyRemoveStyle}},{}],9:[function(require,module,exports){"use strict";function isUndef(e){return void 0===e}function isDef(e){return void 0!==e}function sameVnode(e,t){return e.key===t.key&&e.sel===t.sel}function createKeyToOldIdx(e,t,i){var n,o,r={};for(n=t;n<=i;++n)o=e[n].key,isDef(o)&&(r[o]=n);return r}function init(e,t){function i(e){var i=e.id?"#"+e.id:"",n=e.className?"."+e.className.split(" ").join("."):"";return VNode(t.tagName(e).toLowerCase()+i+n,{},[],void 0,e)}function n(e,i){return function(){if(0===--i){var n=t.parentNode(e);t.removeChild(n,e)}}}function o(e,i){var n,r=e.data;isDef(r)&&isDef(n=r.hook)&&isDef(n=n.init)&&(n(e),r=e.data);var s,f=e.children,d=e.sel;if(isDef(d)){var l=d.indexOf("#"),a=d.indexOf(".",l),m=l>0?l:d.length,c=a>0?a:d.length,u=l!==-1||a!==-1?d.slice(0,Math.min(m,c)):d;if(s=e.elm=isDef(r)&&isDef(n=r.ns)?t.createElementNS(n,u):t.createElement(u),m<c&&(s.id=d.slice(m+1,c)),a>0&&(s.className=d.slice(c+1).replace(/\./g," ")),is.array(f))for(n=0;n<f.length;++n)t.appendChild(s,o(f[n],i));else is.primitive(e.text)&&t.appendChild(s,t.createTextNode(e.text));for(n=0;n<h.create.length;++n)h.create[n](emptyNode,e);n=e.data.hook,isDef(n)&&(n.create&&n.create(emptyNode,e),n.insert&&i.push(e))}else s=e.elm=t.createTextNode(e.text);return e.elm}function r(e,i,n,r,s,f){for(;r<=s;++r)t.insertBefore(e,o(n[r],f),i)}function s(e){var t,i,n=e.data;if(isDef(n)){for(isDef(t=n.hook)&&isDef(t=t.destroy)&&t(e),t=0;t<h.destroy.length;++t)h.destroy[t](e);if(isDef(t=e.children))for(i=0;i<e.children.length;++i)s(e.children[i])}}function f(e,i,o,r){for(;o<=r;++o){var f,d,l,a=i[o];if(isDef(a))if(isDef(a.sel)){for(s(a),d=h.remove.length+1,l=n(a.elm,d),f=0;f<h.remove.length;++f)h.remove[f](a,l);isDef(f=a.data)&&isDef(f=f.hook)&&isDef(f=f.remove)?f(a,l):l()}else t.removeChild(e,a.elm)}}function d(e,i,n,s){for(var d,a,m,h,c=0,u=0,p=i.length-1,v=i[0],D=i[p],g=n.length-1,x=n[0],k=n[g];c<=p&&u<=g;)isUndef(v)?v=i[++c]:isUndef(D)?D=i[--p]:sameVnode(v,x)?(l(v,x,s),v=i[++c],x=n[++u]):sameVnode(D,k)?(l(D,k,s),D=i[--p],k=n[--g]):sameVnode(v,k)?(l(v,k,s),t.insertBefore(e,v.elm,t.nextSibling(D.elm)),v=i[++c],k=n[--g]):sameVnode(D,x)?(l(D,x,s),t.insertBefore(e,D.elm,v.elm),D=i[--p],x=n[++u]):(isUndef(d)&&(d=createKeyToOldIdx(i,c,p)),a=d[x.key],isUndef(a)?(t.insertBefore(e,o(x,s),v.elm),x=n[++u]):(m=i[a],l(m,x,s),i[a]=void 0,t.insertBefore(e,m.elm,v.elm),x=n[++u]));c>p?(h=isUndef(n[g+1])?null:n[g+1].elm,r(e,h,n,u,g,s)):u>g&&f(e,i,c,p)}function l(e,i,n){var s,l;isDef(s=i.data)&&isDef(l=s.hook)&&isDef(s=l.prepatch)&&s(e,i);var a=i.elm=e.elm,m=e.children,c=i.children;if(e!==i){if(!sameVnode(e,i)){var u=t.parentNode(e.elm);return a=o(i,n),t.insertBefore(u,a,e.elm),void f(u,[e],0,0)}if(isDef(i.data)){for(s=0;s<h.update.length;++s)h.update[s](e,i);s=i.data.hook,isDef(s)&&isDef(s=s.update)&&s(e,i)}isUndef(i.text)?isDef(m)&&isDef(c)?m!==c&&d(a,m,c,n):isDef(c)?(isDef(e.text)&&t.setTextContent(a,""),r(a,null,c,0,c.length-1,n)):isDef(m)?f(a,m,0,m.length-1):isDef(e.text)&&t.setTextContent(a,""):e.text!==i.text&&t.setTextContent(a,i.text),isDef(l)&&isDef(s=l.postpatch)&&s(e,i)}}var a,m,h={};for(isUndef(t)&&(t=domApi),a=0;a<hooks.length;++a)for(h[hooks[a]]=[],m=0;m<e.length;++m)void 0!==e[m][hooks[a]]&&h[hooks[a]].push(e[m][hooks[a]]);return function(e,n){var r,s,d,a=[];for(r=0;r<h.pre.length;++r)h.pre[r]();for(isUndef(e.sel)&&(e=i(e)),sameVnode(e,n)?l(e,n,a):(s=e.elm,d=t.parentNode(s),o(n,a),null!==d&&(t.insertBefore(d,n.elm,t.nextSibling(s)),f(d,[e],0,0))),r=0;r<a.length;++r)a[r].data.hook.insert(a[r]);for(r=0;r<h.post.length;++r)h.post[r]();return n}}var VNode=require("./vnode"),is=require("./is"),domApi=require("./htmldomapi"),emptyNode=VNode("",{},[],void 0,void 0),hooks=["create","update","remove","destroy","pre","post"];module.exports={init:init}},{"./htmldomapi":2,"./is":3,"./vnode":10}],10:[function(require,module,exports){module.exports=function(e,t,d,o,r){var i=void 0===t?void 0:t.key;return{sel:e,data:t,children:d,text:o,elm:r,key:i}}},{}]},{},[1])(1)}); |
{ | ||
"name": "flea", | ||
"description": "Front-end library based in Snabbdom and ES6 tagged template literals", | ||
"version": "0.0.14", | ||
"description": "Tiny UI library based in Snabbdom and ES6 tagged template literals", | ||
"version": "0.0.15", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "author": "Jorge Bucaran", |
# flea | ||
Flea is a <4kb JavaScript front-end library based in [Snabbdom] and ES6 tagged template literals with [Hyperx]. | ||
Flea is a <4kb JavaScript UI library based in [Snabbdom] and ES6 tagged template literals with [Hyperx]. | ||
@@ -15,3 +15,3 @@ The API and state management is inspired by the [Elm Architecture] and [choo]. | ||
This is a basic counter app. | ||
A basic counter app. See [fiddle](https://jsfiddle.net/jbucaran/epo7fexz/8/). | ||
@@ -29,3 +29,3 @@ ```js | ||
<h1>${model}</h1> | ||
<button onclick=${msg.sub} disabled=${model === 0}>–</button> | ||
<button onclick=${msg.sub} disabled=${model <= 0}>–</button> | ||
</div>` | ||
@@ -35,3 +35,3 @@ }) | ||
[See more examples](https://flea.gomix.me/) and a [fiddle](https://jsfiddle.net/jbucaran/epo7fexz/1/). | ||
[See live examples](https://flea.gomix.me/). | ||
@@ -42,3 +42,3 @@ ## API | ||
You use `html` to compose HTML elements. | ||
Use `html` to compose HTML elements. | ||
@@ -55,13 +55,13 @@ ```js | ||
The `app` function receives an object with any of the following properties. | ||
The `app` function takes an object with any of the following properties. | ||
#### model | ||
The model is an object with the state of your app. You don't modify the model directly, instead, you call reducers (update functions) that describe how the model will change. This causes the view to be rendered again. | ||
An value or object that represents the state of your app. You don't modify the model directly, instead, dispatch actions that describe how the model will change. See [view](#view). | ||
#### update | ||
The update object exposes reducers that describe how the model will change. A reducer returns a new model. If you find you are doing something different here, you probably want an [effect](#effects) instead. | ||
The update object exposes reducer functions. A reducer describes how the model will change for a given action and can return a new model or part of a model. If a reducer returns part of a model, it will be merged back into the current model. | ||
Reducers have a signature `(model, data)`, where `model` is the current model, and `data` is the data the reducer was passed to. | ||
Reducers have a signature `(model, data)`, where `model` is the current model, and `data` is any data passed into the function. | ||
@@ -74,3 +74,3 @@ You call reducers inside a view, effect or subscription. | ||
The view has a signature `(model, msg)`, where `model` is the current model, and `msg` is a function you use to call reducers / cause effects. | ||
The view has a signature `(model, msg)`, where `model` is the current model, and `msg` is an object you use to call reducers / cause effects. | ||
@@ -89,7 +89,7 @@ ```js | ||
Effects are often asynchronous and cause side effects, like writing to a database, or sending requests to servers. When they are done, they often call a reducer. | ||
Effects are often asynchronous and cause side effects, like writing to a database, or sending requests to servers. When they are done, they often dispatch an action. | ||
Effects have a signature `(model, msg, error)`, where `model` is the current model, `msg` is a function you use to call reducers / cause effects (see [view](#view)), and `error` is a function you may call with an error if something goes wrong. | ||
Effects have a signature `(model, msg, error)`, where `model` is the current model, `msg` is an object you use to call reducers / cause effects (see [view](#view)), and `error` is a function you may call with an error if something goes wrong. | ||
#### subscriptions | ||
#### subs | ||
@@ -104,3 +104,3 @@ Subscriptions are functions that run only once when the [DOM is ready](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded). Use a subscription to register global events, like mouse or keyboard listeners. | ||
Hooks are functions Flea calls when certain events happen across the app. You can use hooks to implement middleware, loggers, etc. | ||
Hooks are functions called when certain events happen across the app. You can use hooks to implement middleware, loggers, etc. | ||
@@ -121,3 +121,3 @@ ##### onUpdate | ||
The root is the HTML element that will serve as a container for your app. If none is given, Flea will create a `div` element in document.body and append your view in it. | ||
The root is the HTML element that will serve as a container for your app. If none is given, a `div` element is appended to the document.body. | ||
@@ -124,0 +124,0 @@ ## FAQ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80
66318