Socket
Socket
Sign inDemoInstall

snabbdom-jsx

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snabbdom-jsx - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

examples/.babelrc

605

examples/counter/build.js
(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){
/** @jsx html */
'use strict';
Object.defineProperty(exports, '__esModule', {
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _snabbdomJsx = require('../../../snabbdom-jsx');

@@ -18,3 +14,7 @@

var Action = (0, _unionType2['default'])({
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** @jsx html */
var Action = (0, _unionType2.default)({
Increment: [],

@@ -56,3 +56,3 @@ Decrement: []

function update(count, action) {
return Action['case']({
return Action.case({
Increment: function Increment() {

@@ -67,20 +67,13 @@ return count + 1;

exports['default'] = { view: view, init: init, update: update, Action: Action };
module.exports = exports['default'];
exports.default = { view: view, init: init, update: update, Action: Action };
},{"../../../snabbdom-jsx":17,"union-type":16}],2:[function(require,module,exports){
/** @jsx html */
'use strict';
Object.defineProperty(exports, '__esModule', {
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _snabbdomJsx = require('../../../snabbdom-jsx');

@@ -96,7 +89,11 @@

var Action = (0, _unionType2['default'])({
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /** @jsx html */
var Action = (0, _unionType2.default)({
Add: [],
Remove: [Number],
Reset: [],
Update: [Number, _counter2['default'].Action]
Update: [Number, _counter2.default.Action]
});

@@ -140,3 +137,3 @@

var item = _ref2.item;
var handler = _ref2.handler;
var _handler = _ref2.handler;
return (0, _snabbdomJsx.html)(

@@ -148,9 +145,9 @@ 'div',

{
'on-click': [handler, Action.Remove(item.id)] },
'on-click': [_handler, Action.Remove(item.id)] },
'Remove'
),
(0, _snabbdomJsx.html)(_counter2['default'], {
(0, _snabbdomJsx.html)(_counter2.default, {
model: item.counter,
handler: function (a) {
return handler(Action.Update(item.id, a));
handler: function handler(a) {
return _handler(Action.Update(item.id, a));
} })

@@ -165,3 +162,3 @@ );

function addCounter(model) {
var newCounter = { id: model.nextID, counter: _counter2['default'].init() };
var newCounter = { id: model.nextID, counter: _counter2.default.init() };
return {

@@ -178,3 +175,3 @@ counters: [].concat(_toConsumableArray(model.counters), [newCounter]),

return _extends({}, item, {
counter: _counter2['default'].init()
counter: _counter2.default.init()
});

@@ -197,3 +194,3 @@ })

return item.id !== id ? item : _extends({}, item, {
counter: _counter2['default'].update(item.counter, action)
counter: _counter2.default.update(item.counter, action)
});

@@ -206,3 +203,3 @@ })

return Action['case']({
return Action.case({
Add: function Add() {

@@ -223,4 +220,3 @@ return addCounter(model);

exports['default'] = { view: view, init: init, update: update, Action: Action };
module.exports = exports['default'];
exports.default = { view: view, init: init, update: update, Action: Action };

@@ -230,4 +226,2 @@ },{"../../../snabbdom-jsx":17,"./counter":1,"union-type":16}],3:[function(require,module,exports){

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _snabbdom = require('snabbdom');

@@ -241,3 +235,5 @@

var patch = _snabbdom2['default'].init([require('snabbdom/modules/class'), // makes it easy to toggle classes
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var patch = _snabbdom2.default.init([require('snabbdom/modules/class'), // makes it easy to toggle classes
require('snabbdom/modules/props'), // for setting properties on DOM elements

@@ -262,6 +258,203 @@ require('snabbdom/modules/style'), // handles styling on elements with support for animations

main(_counterList2['default'].init(), // the initial state
document.getElementById('placeholder'), _counterList2['default']);
main(_counterList2.default.init(), // the initial state
document.getElementById('placeholder'), _counterList2.default);
},{"./counterList":2,"snabbdom":9,"snabbdom/modules/class":5,"snabbdom/modules/eventlisteners":6,"snabbdom/modules/props":7,"snabbdom/modules/style":8}],4:[function(require,module,exports){
},{"./counterList":2,"snabbdom":14,"snabbdom/modules/class":10,"snabbdom/modules/eventlisteners":11,"snabbdom/modules/props":12,"snabbdom/modules/style":13}],4:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
/**
* Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
* parameters. Unlike `nAry`, which passes only `n` arguments to the wrapped function,
* functions produced by `arity` will pass all provided arguments to the wrapped function.
*
* @func
* @memberOf R
* @sig (Number, (* -> *)) -> (* -> *)
* @category Function
* @param {Number} n The desired arity of the returned function.
* @param {Function} fn The function to wrap.
* @return {Function} A new function wrapping `fn`. The new function is
* guaranteed to be of arity `n`.
* @deprecated since v0.15.0
* @example
*
* var takesTwoArgs = function(a, b) {
* return [a, b];
* };
* takesTwoArgs.length; //=> 2
* takesTwoArgs(1, 2); //=> [1, 2]
*
* var takesOneArg = R.arity(1, takesTwoArgs);
* takesOneArg.length; //=> 1
* // All arguments are passed through to the wrapped function
* takesOneArg(1, 2); //=> [1, 2]
*/
module.exports = _curry2(function(n, fn) {
// jshint unused:vars
switch (n) {
case 0: return function() {return fn.apply(this, arguments);};
case 1: return function(a0) {return fn.apply(this, arguments);};
case 2: return function(a0, a1) {return fn.apply(this, arguments);};
case 3: return function(a0, a1, a2) {return fn.apply(this, arguments);};
case 4: return function(a0, a1, a2, a3) {return fn.apply(this, arguments);};
case 5: return function(a0, a1, a2, a3, a4) {return fn.apply(this, arguments);};
case 6: return function(a0, a1, a2, a3, a4, a5) {return fn.apply(this, arguments);};
case 7: return function(a0, a1, a2, a3, a4, a5, a6) {return fn.apply(this, arguments);};
case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) {return fn.apply(this, arguments);};
case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) {return fn.apply(this, arguments);};
case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {return fn.apply(this, arguments);};
default: throw new Error('First argument to arity must be a non-negative integer no greater than ten');
}
});
},{"./internal/_curry2":7}],5:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
var _curryN = require('./internal/_curryN');
var arity = require('./arity');
/**
* Returns a curried equivalent of the provided function, with the
* specified arity. The curried function has two unusual capabilities.
* First, its arguments needn't be provided one at a time. If `g` is
* `R.curryN(3, f)`, the following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value `R.__` may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is `R.__`,
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
* @param {Number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curry
* @example
*
* var addFourNumbers = function() {
* return R.sum([].slice.call(arguments, 0, 4));
* };
*
* var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*/
module.exports = _curry2(function curryN(length, fn) {
return arity(length, _curryN(length, [], fn));
});
},{"./arity":4,"./internal/_curry2":7,"./internal/_curryN":8}],6:[function(require,module,exports){
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0) {
return f1;
} else if (a != null && a['@@functional/placeholder'] === true) {
return f1;
} else {
return fn(a);
}
};
};
},{}],7:[function(require,module,exports){
var _curry1 = require('./_curry1');
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
var n = arguments.length;
if (n === 0) {
return f2;
} else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
return f2;
} else if (n === 1) {
return _curry1(function(b) { return fn(a, b); });
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true &&
b != null && b['@@functional/placeholder'] === true) {
return f2;
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
return _curry1(function(a) { return fn(a, b); });
} else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
return _curry1(function(b) { return fn(a, b); });
} else {
return fn(a, b);
}
};
};
},{"./_curry1":6}],8:[function(require,module,exports){
var arity = require('../arity');
/**
* Internal curryN function.
*
* @private
* @category Function
* @param {Number} length The arity of the curried function.
* @return {array} An array of arguments received thus far.
* @param {Function} fn The function to curry.
*/
module.exports = function _curryN(length, received, fn) {
return function() {
var combined = [];
var argsIdx = 0;
var left = length;
var combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
var result;
if (combinedIdx < received.length &&
(received[combinedIdx] == null ||
received[combinedIdx]['@@functional/placeholder'] !== true ||
argsIdx >= arguments.length)) {
result = received[combinedIdx];
} else {
result = arguments[argsIdx];
argsIdx += 1;
}
combined[combinedIdx] = result;
if (result == null || result['@@functional/placeholder'] !== true) {
left -= 1;
}
combinedIdx += 1;
}
return left <= 0 ? fn.apply(this, combined) : arity(left, _curryN(length, combined, fn));
};
};
},{"../arity":4}],9:[function(require,module,exports){
module.exports = {

@@ -272,3 +465,3 @@ array: Array.isArray,

},{}],5:[function(require,module,exports){
},{}],10:[function(require,module,exports){
function updateClass(oldVnode, vnode) {

@@ -288,3 +481,3 @@ var cur, name, elm = vnode.elm,

},{}],6:[function(require,module,exports){
},{}],11:[function(require,module,exports){
var is = require('../is');

@@ -332,3 +525,3 @@

},{"../is":4}],7:[function(require,module,exports){
},{"../is":9}],12:[function(require,module,exports){
function updateProps(oldVnode, vnode) {

@@ -348,3 +541,3 @@ var key, cur, old, elm = vnode.elm,

},{}],8:[function(require,module,exports){
},{}],13:[function(require,module,exports){
var raf = requestAnimationFrame || setTimeout;

@@ -410,3 +603,3 @@ var nextFrame = function(fn) { raf(function() { raf(fn); }); };

},{}],9:[function(require,module,exports){
},{}],14:[function(require,module,exports){
// jshint newcap: false

@@ -428,4 +621,2 @@ /* global require, module, document, Element */

var insertedVnodeQueue;
function sameVnode(vnode1, vnode2) {

@@ -461,3 +652,3 @@ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;

function createElm(vnode) {
function createElm(vnode, insertedVnodeQueue) {
var i, data = vnode.data;

@@ -482,3 +673,3 @@ if (isDef(data)) {

for (i = 0; i < children.length; ++i) {
elm.appendChild(createElm(children[i]));
elm.appendChild(createElm(children[i], insertedVnodeQueue));
}

@@ -500,5 +691,5 @@ } else if (is.primitive(vnode.text)) {

function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
for (; startIdx <= endIdx; ++startIdx) {
parentElm.insertBefore(createElm(vnodes[startIdx]), before);
parentElm.insertBefore(createElm(vnodes[startIdx], insertedVnodeQueue), before);
}

@@ -541,3 +732,3 @@ }

function updateChildren(parentElm, oldCh, newCh) {
function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) {
var oldStartIdx = 0, newStartIdx = 0;

@@ -558,11 +749,11 @@ var oldEndIdx = oldCh.length - 1;

} else if (sameVnode(oldStartVnode, newStartVnode)) {
patchVnode(oldStartVnode, newStartVnode);
patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode)) {
patchVnode(oldEndVnode, newEndVnode);
patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
patchVnode(oldStartVnode, newEndVnode);
patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
parentElm.insertBefore(oldStartVnode.elm, oldEndVnode.elm.nextSibling);

@@ -572,3 +763,3 @@ oldStartVnode = oldCh[++oldStartIdx];

} else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
patchVnode(oldEndVnode, newStartVnode);
patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
parentElm.insertBefore(oldEndVnode.elm, oldStartVnode.elm);

@@ -581,7 +772,7 @@ oldEndVnode = oldCh[--oldEndIdx];

if (isUndef(idxInOld)) { // New element
parentElm.insertBefore(createElm(newStartVnode), oldStartVnode.elm);
parentElm.insertBefore(createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
patchVnode(elmToMove, newStartVnode);
patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
oldCh[idxInOld] = undefined;

@@ -595,3 +786,3 @@ parentElm.insertBefore(elmToMove.elm, oldStartVnode.elm);

before = isUndef(newCh[newEndIdx+1]) ? null : newCh[newEndIdx+1].elm;
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
} else if (newStartIdx > newEndIdx) {

@@ -602,3 +793,3 @@ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);

function patchVnode(oldVnode, vnode) {
function patchVnode(oldVnode, vnode, insertedVnodeQueue) {
var i, hook;

@@ -619,5 +810,5 @@ if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {

if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(elm, oldCh, ch);
if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue);
} else if (isDef(ch)) {
addVnodes(elm, null, ch, 0, ch.length - 1);
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
} else if (isDef(oldCh)) {

@@ -632,3 +823,2 @@ removeVnodes(elm, oldCh, 0, oldCh.length - 1);

}
return vnode;
}

@@ -638,14 +828,14 @@

var i;
insertedVnodeQueue = [];
var insertedVnodeQueue = [];
for (i = 0; i < cbs.pre.length; ++i) cbs.pre[i]();
if (oldVnode instanceof Element) {
if (oldVnode.parentElement !== null) {
createElm(vnode);
createElm(vnode, insertedVnodeQueue);
oldVnode.parentElement.replaceChild(vnode.elm, oldVnode);
} else {
oldVnode = emptyNodeAt(oldVnode);
patchVnode(oldVnode, vnode);
patchVnode(oldVnode, vnode, insertedVnodeQueue);
}
} else {
patchVnode(oldVnode, vnode);
patchVnode(oldVnode, vnode, insertedVnodeQueue);
}

@@ -655,3 +845,2 @@ for (i = 0; i < insertedVnodeQueue.length; ++i) {

}
insertedVnodeQueue = undefined;
for (i = 0; i < cbs.post.length; ++i) cbs.post[i]();

@@ -664,3 +853,3 @@ return vnode;

},{"./is":4,"./vnode":10}],10:[function(require,module,exports){
},{"./is":9,"./vnode":15}],15:[function(require,module,exports){
module.exports = function(sel, data, children, text, elm) {

@@ -672,200 +861,3 @@ var key = data === undefined ? undefined : data.key;

},{}],11:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
/**
* Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
* parameters. Unlike `nAry`, which passes only `n` arguments to the wrapped function,
* functions produced by `arity` will pass all provided arguments to the wrapped function.
*
* @func
* @memberOf R
* @sig (Number, (* -> *)) -> (* -> *)
* @category Function
* @param {Number} n The desired arity of the returned function.
* @param {Function} fn The function to wrap.
* @return {Function} A new function wrapping `fn`. The new function is
* guaranteed to be of arity `n`.
* @deprecated since v0.15.0
* @example
*
* var takesTwoArgs = function(a, b) {
* return [a, b];
* };
* takesTwoArgs.length; //=> 2
* takesTwoArgs(1, 2); //=> [1, 2]
*
* var takesOneArg = R.arity(1, takesTwoArgs);
* takesOneArg.length; //=> 1
* // All arguments are passed through to the wrapped function
* takesOneArg(1, 2); //=> [1, 2]
*/
module.exports = _curry2(function(n, fn) {
// jshint unused:vars
switch (n) {
case 0: return function() {return fn.apply(this, arguments);};
case 1: return function(a0) {return fn.apply(this, arguments);};
case 2: return function(a0, a1) {return fn.apply(this, arguments);};
case 3: return function(a0, a1, a2) {return fn.apply(this, arguments);};
case 4: return function(a0, a1, a2, a3) {return fn.apply(this, arguments);};
case 5: return function(a0, a1, a2, a3, a4) {return fn.apply(this, arguments);};
case 6: return function(a0, a1, a2, a3, a4, a5) {return fn.apply(this, arguments);};
case 7: return function(a0, a1, a2, a3, a4, a5, a6) {return fn.apply(this, arguments);};
case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) {return fn.apply(this, arguments);};
case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) {return fn.apply(this, arguments);};
case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {return fn.apply(this, arguments);};
default: throw new Error('First argument to arity must be a non-negative integer no greater than ten');
}
});
},{"./internal/_curry2":14}],12:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
var _curryN = require('./internal/_curryN');
var arity = require('./arity');
/**
* Returns a curried equivalent of the provided function, with the
* specified arity. The curried function has two unusual capabilities.
* First, its arguments needn't be provided one at a time. If `g` is
* `R.curryN(3, f)`, the following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value `R.__` may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is `R.__`,
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
* @param {Number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curry
* @example
*
* var addFourNumbers = function() {
* return R.sum([].slice.call(arguments, 0, 4));
* };
*
* var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*/
module.exports = _curry2(function curryN(length, fn) {
return arity(length, _curryN(length, [], fn));
});
},{"./arity":11,"./internal/_curry2":14,"./internal/_curryN":15}],13:[function(require,module,exports){
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0) {
return f1;
} else if (a != null && a['@@functional/placeholder'] === true) {
return f1;
} else {
return fn(a);
}
};
};
},{}],14:[function(require,module,exports){
var _curry1 = require('./_curry1');
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
var n = arguments.length;
if (n === 0) {
return f2;
} else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
return f2;
} else if (n === 1) {
return _curry1(function(b) { return fn(a, b); });
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true &&
b != null && b['@@functional/placeholder'] === true) {
return f2;
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
return _curry1(function(a) { return fn(a, b); });
} else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
return _curry1(function(b) { return fn(a, b); });
} else {
return fn(a, b);
}
};
};
},{"./_curry1":13}],15:[function(require,module,exports){
var arity = require('../arity');
/**
* Internal curryN function.
*
* @private
* @category Function
* @param {Number} length The arity of the curried function.
* @return {array} An array of arguments received thus far.
* @param {Function} fn The function to curry.
*/
module.exports = function _curryN(length, received, fn) {
return function() {
var combined = [];
var argsIdx = 0;
var left = length;
var combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
var result;
if (combinedIdx < received.length &&
(received[combinedIdx] == null ||
received[combinedIdx]['@@functional/placeholder'] !== true ||
argsIdx >= arguments.length)) {
result = received[combinedIdx];
} else {
result = arguments[argsIdx];
argsIdx += 1;
}
combined[combinedIdx] = result;
if (result == null || result['@@functional/placeholder'] !== true) {
left -= 1;
}
combinedIdx += 1;
}
return left <= 0 ? fn.apply(this, combined) : arity(left, _curryN(length, combined, fn));
};
};
},{"../arity":11}],16:[function(require,module,exports){
},{}],16:[function(require,module,exports){
var curryN = require('ramda/src/curryN');

@@ -940,27 +932,26 @@

},{"ramda/src/curryN":12}],17:[function(require,module,exports){
'use strict';
},{"ramda/src/curryN":5}],17:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.html = html;
exports.svg = svg;
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
var SVGNS = "http://www.w3.org/2000/svg";
var modulesNS = ['key', 'on', 'style', 'class', 'props'];
var SVGNS = 'http://www.w3.org/2000/svg';
var modulesNS = ['hook', 'on', 'style', 'class', 'props', 'attrs'];
var slice = Array.prototype.slice;
function isPrimitive(val) {
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || typeof val === 'symbol' || val === null || val === undefined;
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'symbol' || val === null || val === undefined;
}
function normalizeAttrs(attrs, ns) {
var map = { ns: ns };
for (var i = 0, len = modulesNS.length; i < len; i++) {
var modNS = modulesNS[i];
if (attrs[modNS]) map[modNS] = attrs[modNS];
function normalizeAttrs(attrs, nsURI, defNS, modules) {
var map = { ns: nsURI };
for (var i = 0, len = modules.length; i < len; i++) {
var mod = modules[i];
if (attrs[mod]) map[mod] = attrs[mod];
}
for (var key in attrs) {
var parts = key.split('-');
if (parts.length > 1) addAttr(parts[0], parts[1], attrs[key]);else addAttr('props', parts[0], attrs[key]);
if (key !== 'key' && key !== 'classNames' && key !== 'selector') {
var idx = key.indexOf('-');
if (idx > 0) addAttr(key.slice(0, idx), key.slice(idx + 1), attrs[key]);else if (!map[key]) addAttr(defNS, key, attrs[key]);
}
}

@@ -975,4 +966,7 @@ return map;

function jsx(ns, tag, attrs, children) {
attrs = attrs || {};
function buildFromStringTag(nsURI, defNS, modules, tag, attrs, children) {
if (attrs.selector) {
tag = tag + attrs.selector;
}
if (attrs.classNames) {

@@ -982,29 +976,42 @@ var cns = attrs.classNames;

}
if (typeof tag === 'string') return {
return {
sel: tag,
data: normalizeAttrs(attrs, ns),
data: normalizeAttrs(attrs, nsURI, defNS, modules),
children: children.map(function (c) {
return isPrimitive(c) ? { text: c } : c;
})
};else if (typeof tag === 'function') return tag(attrs, children);else if (tag && typeof tag.view === 'function') return tag.view(attrs, children);
}),
key: attrs.key
};
}
function html(tag, attrs) {
for (var _len = arguments.length, children = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
children[_key - 2] = arguments[_key];
}
if (arguments.length === 3 && Array.isArray(arguments[2])) children = arguments[2];
return jsx(undefined, tag, attrs, children);
function buildFromComponent(nsURI, defNS, modules, tag, attrs, children) {
var res;
if (typeof tag === 'function') res = tag(attrs, children);else if (tag && typeof tag.view === 'function') res = tag.view(attrs, children);else if (tag && typeof tag.render === 'function') res = tag.render(attrs, children);else throw "JSX tag must be either a string, a function or an object with 'view' or 'render' methods";
res.key = attrs.key;
return res;
}
function svg(tag, attrs) {
for (var _len2 = arguments.length, children = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
children[_key2 - 2] = arguments[_key2];
function buildVnode(nsURI, defNS, modules, tag, attrs, children) {
attrs = attrs || {};
if (typeof tag === 'string') {
return buildFromStringTag(nsURI, defNS, modules, tag, attrs, children);
} else {
return buildFromComponent(nsURI, defNS, modules, tag, attrs, children);
}
}
if (arguments.length === 3 && Array.isArray(arguments[2])) children = arguments[2];
return jsx(SVGNS, tag, attrs, children);
function JSX(nsURI, defNS, modules) {
return function jsxWithCustomNS(tag, attrs, children) {
if (arguments.length > 3 || !Array.isArray(children)) children = slice.call(arguments, 2);
return buildVnode(nsURI, defNS || 'props', modules || modulesNS, tag, attrs, children);
};
}
module.exports = {
html: JSX(undefined),
svg: JSX(SVGNS, 'attrs'),
JSX: JSX
};
},{}]},{},[3]);
(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){
/** @jsx html */
'use strict';
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _snabbdomJsx = require('../../snabbdom-jsx');

@@ -14,5 +10,9 @@

var patch = _snabbdom2['default'].init([require('snabbdom/modules/class'), require('snabbdom/modules/props'), require('snabbdom/modules/style'), require('snabbdom/modules/eventlisteners')]);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//MyDiv : (attrs, body) -> vnode
/** @jsx html */
var patch = _snabbdom2.default.init([require('snabbdom/modules/class'), require('snabbdom/modules/props'), require('snabbdom/modules/style'), require('snabbdom/modules/eventlisteners')]);
//HelloMessage : (attrs, body) -> vnode
var HelloMessage = function HelloMessage(_ref) {

@@ -22,3 +22,3 @@ var name = _ref.name;

'div',
{ 'on-click': function (_) {
{ 'on-click': function onClick(_) {
return alert('Hi ' + name);

@@ -191,4 +191,2 @@ } },

var insertedVnodeQueue;
function sameVnode(vnode1, vnode2) {

@@ -224,3 +222,3 @@ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;

function createElm(vnode) {
function createElm(vnode, insertedVnodeQueue) {
var i, data = vnode.data;

@@ -245,3 +243,3 @@ if (isDef(data)) {

for (i = 0; i < children.length; ++i) {
elm.appendChild(createElm(children[i]));
elm.appendChild(createElm(children[i], insertedVnodeQueue));
}

@@ -263,5 +261,5 @@ } else if (is.primitive(vnode.text)) {

function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
for (; startIdx <= endIdx; ++startIdx) {
parentElm.insertBefore(createElm(vnodes[startIdx]), before);
parentElm.insertBefore(createElm(vnodes[startIdx], insertedVnodeQueue), before);
}

@@ -304,3 +302,3 @@ }

function updateChildren(parentElm, oldCh, newCh) {
function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) {
var oldStartIdx = 0, newStartIdx = 0;

@@ -321,11 +319,11 @@ var oldEndIdx = oldCh.length - 1;

} else if (sameVnode(oldStartVnode, newStartVnode)) {
patchVnode(oldStartVnode, newStartVnode);
patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode)) {
patchVnode(oldEndVnode, newEndVnode);
patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
patchVnode(oldStartVnode, newEndVnode);
patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
parentElm.insertBefore(oldStartVnode.elm, oldEndVnode.elm.nextSibling);

@@ -335,3 +333,3 @@ oldStartVnode = oldCh[++oldStartIdx];

} else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
patchVnode(oldEndVnode, newStartVnode);
patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
parentElm.insertBefore(oldEndVnode.elm, oldStartVnode.elm);

@@ -344,7 +342,7 @@ oldEndVnode = oldCh[--oldEndIdx];

if (isUndef(idxInOld)) { // New element
parentElm.insertBefore(createElm(newStartVnode), oldStartVnode.elm);
parentElm.insertBefore(createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
patchVnode(elmToMove, newStartVnode);
patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
oldCh[idxInOld] = undefined;

@@ -358,3 +356,3 @@ parentElm.insertBefore(elmToMove.elm, oldStartVnode.elm);

before = isUndef(newCh[newEndIdx+1]) ? null : newCh[newEndIdx+1].elm;
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
} else if (newStartIdx > newEndIdx) {

@@ -365,3 +363,3 @@ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);

function patchVnode(oldVnode, vnode) {
function patchVnode(oldVnode, vnode, insertedVnodeQueue) {
var i, hook;

@@ -382,5 +380,5 @@ if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {

if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(elm, oldCh, ch);
if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue);
} else if (isDef(ch)) {
addVnodes(elm, null, ch, 0, ch.length - 1);
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
} else if (isDef(oldCh)) {

@@ -395,3 +393,2 @@ removeVnodes(elm, oldCh, 0, oldCh.length - 1);

}
return vnode;
}

@@ -401,14 +398,14 @@

var i;
insertedVnodeQueue = [];
var insertedVnodeQueue = [];
for (i = 0; i < cbs.pre.length; ++i) cbs.pre[i]();
if (oldVnode instanceof Element) {
if (oldVnode.parentElement !== null) {
createElm(vnode);
createElm(vnode, insertedVnodeQueue);
oldVnode.parentElement.replaceChild(vnode.elm, oldVnode);
} else {
oldVnode = emptyNodeAt(oldVnode);
patchVnode(oldVnode, vnode);
patchVnode(oldVnode, vnode, insertedVnodeQueue);
}
} else {
patchVnode(oldVnode, vnode);
patchVnode(oldVnode, vnode, insertedVnodeQueue);
}

@@ -418,3 +415,2 @@ for (i = 0; i < insertedVnodeQueue.length; ++i) {

}
insertedVnodeQueue = undefined;
for (i = 0; i < cbs.post.length; ++i) cbs.post[i]();

@@ -437,8 +433,10 @@ return vnode;

var SVGNS = "http://www.w3.org/2000/svg";
var modulesNS = ['key', 'on', 'style', 'class', 'props'];
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
var SVGNS = 'http://www.w3.org/2000/svg';
var modulesNS = ['hook', 'on', 'style', 'class', 'props', 'attrs'];
var slice = Array.prototype.slice;
function isPrimitive(val) {
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || typeof val === 'symbol' || val === null || val === undefined;
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'symbol' || val === null || val === undefined;
}

@@ -453,4 +451,6 @@

for (var key in attrs) {
var parts = key.split('-');
if (parts.length > 1) addAttr(parts[0], parts[1], attrs[key]);else if (!map[key]) addAttr(defNS, parts[0], attrs[key]);
if (key !== 'key' && key !== 'classNames' && key !== 'selector') {
var idx = key.indexOf('-');
if (idx > 0) addAttr(key.slice(0, idx), key.slice(idx + 1), attrs[key]);else if (!map[key]) addAttr(defNS, key, attrs[key]);
}
}

@@ -465,4 +465,7 @@ return map;

function jsx(nsURI, defNS, modules, tag, attrs, children) {
attrs = attrs || {};
function buildFromStringTag(nsURI, defNS, modules, tag, attrs, children) {
if (attrs.selector) {
tag = tag + attrs.selector;
}
if (attrs.classNames) {

@@ -472,11 +475,27 @@ var cns = attrs.classNames;

}
return {
sel: tag,
data: normalizeAttrs(attrs, nsURI, defNS, modules),
children: children.map(function (c) {
return isPrimitive(c) ? { text: c } : c;
}),
key: attrs.key
};
}
function buildFromComponent(nsURI, defNS, modules, tag, attrs, children) {
var res;
if (typeof tag === 'function') res = tag(attrs, children);else if (tag && typeof tag.view === 'function') res = tag.view(attrs, children);else if (tag && typeof tag.render === 'function') res = tag.render(attrs, children);else throw "JSX tag must be either a string, a function or an object with 'view' or 'render' methods";
res.key = attrs.key;
return res;
}
function buildVnode(nsURI, defNS, modules, tag, attrs, children) {
attrs = attrs || {};
if (typeof tag === 'string') {
return {
sel: tag,
data: normalizeAttrs(attrs, nsURI, defNS, modules),
children: children.map(function (c) {
return isPrimitive(c) ? { text: c } : c;
})
};
} else if (typeof tag === 'function') return tag(attrs, children);else if (tag && typeof tag.view === 'function') return tag.view(attrs, children);
return buildFromStringTag(nsURI, defNS, modules, tag, attrs, children);
} else {
return buildFromComponent(nsURI, defNS, modules, tag, attrs, children);
}
}

@@ -487,3 +506,3 @@

if (arguments.length > 3 || !Array.isArray(children)) children = slice.call(arguments, 2);
return jsx(nsURI, defNS || 'props', modules || modulesNS, tag, attrs, children);
return buildVnode(nsURI, defNS || 'props', modules || modulesNS, tag, attrs, children);
};

@@ -490,0 +509,0 @@ }

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _curry2 = require('./internal/_curry2');
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.isBoolean = isBoolean;
exports.bind = bind;
exports.pipe = pipe;
function isBoolean(arg) {
return typeof arg === 'boolean';
}
function bind(fn) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
/**
* Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
* parameters. Unlike `nAry`, which passes only `n` arguments to the wrapped function,
* functions produced by `arity` will pass all provided arguments to the wrapped function.
*
* @func
* @memberOf R
* @sig (Number, (* -> *)) -> (* -> *)
* @category Function
* @param {Number} n The desired arity of the returned function.
* @param {Function} fn The function to wrap.
* @return {Function} A new function wrapping `fn`. The new function is
* guaranteed to be of arity `n`.
* @deprecated since v0.15.0
* @example
*
* var takesTwoArgs = function(a, b) {
* return [a, b];
* };
* takesTwoArgs.length; //=> 2
* takesTwoArgs(1, 2); //=> [1, 2]
*
* var takesOneArg = R.arity(1, takesTwoArgs);
* takesOneArg.length; //=> 1
* // All arguments are passed through to the wrapped function
* takesOneArg(1, 2); //=> [1, 2]
*/
module.exports = _curry2(function(n, fn) {
// jshint unused:vars
switch (n) {
case 0: return function() {return fn.apply(this, arguments);};
case 1: return function(a0) {return fn.apply(this, arguments);};
case 2: return function(a0, a1) {return fn.apply(this, arguments);};
case 3: return function(a0, a1, a2) {return fn.apply(this, arguments);};
case 4: return function(a0, a1, a2, a3) {return fn.apply(this, arguments);};
case 5: return function(a0, a1, a2, a3, a4) {return fn.apply(this, arguments);};
case 6: return function(a0, a1, a2, a3, a4, a5) {return fn.apply(this, arguments);};
case 7: return function(a0, a1, a2, a3, a4, a5, a6) {return fn.apply(this, arguments);};
case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) {return fn.apply(this, arguments);};
case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) {return fn.apply(this, arguments);};
case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {return fn.apply(this, arguments);};
default: throw new Error('First argument to arity must be a non-negative integer no greater than ten');
}
});
return function () {
for (var _len2 = arguments.length, args2 = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args2[_key2] = arguments[_key2];
}
},{"./internal/_curry2":4}],2:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
var _curryN = require('./internal/_curryN');
var arity = require('./arity');
return fn.apply(undefined, [].concat(args, args2));
};
}
;
/**
* Returns a curried equivalent of the provided function, with the
* specified arity. The curried function has two unusual capabilities.
* First, its arguments needn't be provided one at a time. If `g` is
* `R.curryN(3, f)`, the following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value `R.__` may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is `R.__`,
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
* @param {Number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curry
* @example
*
* var addFourNumbers = function() {
* return R.sum([].slice.call(arguments, 0, 4));
* };
*
* var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*/
module.exports = _curry2(function curryN(length, fn) {
return arity(length, _curryN(length, [], fn));
});
function pipe() {
for (var _len3 = arguments.length, fns = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
fns[_key3] = arguments[_key3];
}
return function () {
var res = fns[0].apply(fns, arguments);
for (var i = 1; i < fns.length; i++) {
res = fns[i](res);
},{"./arity":1,"./internal/_curry2":4,"./internal/_curryN":5}],3:[function(require,module,exports){
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0) {
return f1;
} else if (a != null && a['@@functional/placeholder'] === true) {
return f1;
} else {
return fn(a);
}
return res;
};
}
};
;
},{}],4:[function(require,module,exports){
var _curry1 = require('./_curry1');
},{}],2:[function(require,module,exports){
'use strict';
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _snabbdom = require('snabbdom');
var _snabbdom2 = _interopRequireDefault(_snabbdom);
var _todos = require('./todos');
var _todos2 = _interopRequireDefault(_todos);
var patch = _snabbdom2['default'].init([require('snabbdom/modules/class'), // makes it easy to toggle classes
require('snabbdom/modules/props'), // for setting properties on DOM elements
require('snabbdom/modules/style'), // handles styling on elements with support for animations
require('snabbdom/modules/eventlisteners'), // attaches event listeners
require('./snabbdom-modules/window-events') // attaches event listeners to windows
]);
function main(initState, oldVnode, _ref) {
var view = _ref.view;
var update = _ref.update;
var newVnode = view({
model: initState,
handler: function handler(e) {
var newState = update(initState, e);
main(newState, newVnode, { view: view, update: update });
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
var n = arguments.length;
if (n === 0) {
return f2;
} else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
return f2;
} else if (n === 1) {
return _curry1(function(b) { return fn(a, b); });
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true &&
b != null && b['@@functional/placeholder'] === true) {
return f2;
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
return _curry1(function(a) { return fn(a, b); });
} else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
return _curry1(function(b) { return fn(a, b); });
} else {
return fn(a, b);
}
});
patch(oldVnode, newVnode);
}
main(_todos2['default'].init(), // the initial state
document.getElementById('todoapp'), _todos2['default']);
},{"./snabbdom-modules/window-events":3,"./todos":5,"snabbdom":11,"snabbdom/modules/class":7,"snabbdom/modules/eventlisteners":8,"snabbdom/modules/props":9,"snabbdom/modules/style":10}],3:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _snabbdomModulesEventlisteners = require('snabbdom/modules/eventlisteners');
var _snabbdomModulesEventlisteners2 = _interopRequireDefault(_snabbdomModulesEventlisteners);
function updateWindowEvents(oldVnode, vnode) {
_snabbdomModulesEventlisteners2['default'].update({ elm: window, data: { on: oldVnode.data.windowOn } }, { elm: window, data: { on: vnode.data.windowOn } });
}
exports['default'] = { create: updateWindowEvents, update: updateWindowEvents };
module.exports = exports['default'];
},{"snabbdom/modules/eventlisteners":8}],4:[function(require,module,exports){
/** @jsx html */
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _snabbdomJsx = require('../../../snabbdom-jsx');
var _unionType = require('union-type');
var _unionType2 = _interopRequireDefault(_unionType);
var _helpers = require('./helpers');
var KEY_ENTER = 13;
// model : {id: Number, title: String, done: Boolean, editing: Boolean, editingValue: String }
var Action = (0, _unionType2['default'])({
SetTitle: [String],
Toggle: [_helpers.isBoolean],
StartEdit: [],
CommitEdit: [String],
CancelEdit: []
});
var targetChecked = function targetChecked(e) {
return e.target.checked;
};
};
var targetValue = function targetValue(e) {
return e.target.value;
};
function onInput(handler, e) {
if (e.keyCode === KEY_ENTER) handler(Action.CommitEdit(e.target.value));
}
},{"./_curry1":3}],5:[function(require,module,exports){
var arity = require('../arity');
var view = function view(_ref) {
var model = _ref.model;
var handler = _ref.handler;
var onRemove = _ref.onRemove;
return (0, _snabbdomJsx.html)(
'li',
{
key: model.id,
'class-completed': !!model.done && !model.editing,
'class-editing': model.editing },
(0, _snabbdomJsx.html)(
'div',
{ classNames: 'view' },
(0, _snabbdomJsx.html)('input', {
classNames: 'toggle',
type: 'checkbox',
checked: !!model.done,
'on-click': (0, _helpers.pipe)(targetChecked, Action.Toggle, handler) }),
(0, _snabbdomJsx.html)(
'label',
{
'on-dblclick': (0, _helpers.bind)(handler, Action.StartEdit()) },
model.title
),
(0, _snabbdomJsx.html)('button', {
classNames: 'destroy',
'on-click': onRemove })
),
(0, _snabbdomJsx.html)('input', {
classNames: 'edit',
value: model.title,
'on-blur': (0, _helpers.bind)(handler, Action.CancelEdit()),
'on-keydown': (0, _helpers.bind)(onInput, handler) })
);
};
function init(id, title) {
return { id: id, title: title, done: false, editing: false, editingValue: '' };
}
function update(task, action) {
return Action['case']({
Toggle: function Toggle(done) {
return _extends({}, task, { done: done });
},
StartEdit: function StartEdit() {
return _extends({}, task, { editing: true, editingValue: task.title });
},
CommitEdit: function CommitEdit(title) {
return _extends({}, task, { title: title, editing: false, editingValue: '' });
},
CancelEdit: function CancelEdit(title) {
return _extends({}, task, { editing: false, editingValue: '' });
/**
* Internal curryN function.
*
* @private
* @category Function
* @param {Number} length The arity of the curried function.
* @return {array} An array of arguments received thus far.
* @param {Function} fn The function to curry.
*/
module.exports = function _curryN(length, received, fn) {
return function() {
var combined = [];
var argsIdx = 0;
var left = length;
var combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
var result;
if (combinedIdx < received.length &&
(received[combinedIdx] == null ||
received[combinedIdx]['@@functional/placeholder'] !== true ||
argsIdx >= arguments.length)) {
result = received[combinedIdx];
} else {
result = arguments[argsIdx];
argsIdx += 1;
}
combined[combinedIdx] = result;
if (result == null || result['@@functional/placeholder'] !== true) {
left -= 1;
}
combinedIdx += 1;
}
}, action);
}
exports['default'] = { view: view, init: init, update: update, Action: Action };
module.exports = exports['default'];
},{"../../../snabbdom-jsx":19,"./helpers":1,"union-type":18}],5:[function(require,module,exports){
/** @jsx html */
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _snabbdomJsx = require('../../../snabbdom-jsx');
var _unionType = require('union-type');
var _unionType2 = _interopRequireDefault(_unionType);
var _helpers = require('./helpers');
var _task = require('./task');
var _task2 = _interopRequireDefault(_task);
var KEY_ENTER = 13;
// model : { nextID: Number, editingTitle: String, tasks: [task.model], filter: String }
var Action = (0, _unionType2['default'])({
Add: [String],
Remove: [Number],
Archive: [],
ToggleAll: [_helpers.isBoolean],
Filter: [String],
Modify: [Number, _task2['default'].Action]
});
var targetChecked = function targetChecked(e) {
return e.target.checked;
return left <= 0 ? fn.apply(this, combined) : arity(left, _curryN(length, combined, fn));
};
};
var targetValue = function targetValue(e) {
return e.target.value;
};
function onInput(handler, e) {
if (e.keyCode === KEY_ENTER) {
handler(Action.Add(e.target.value));
}
}
function view(_ref) {
var model = _ref.model;
var handler = _ref.handler;
var remaining = remainingTodos(model.tasks);
var filtered = filteredTodos(model.tasks, model.filter);
return (0, _snabbdomJsx.html)(
'section',
{
classNames: 'todoapp',
'windowOn-hashchange': function (_) {
return handler(Action.Filter(window.location.hash.substr(2) || 'all'));
} },
(0, _snabbdomJsx.html)(
'header',
{ classNames: 'header' },
(0, _snabbdomJsx.html)(
'h1',
null,
'todos'
),
(0, _snabbdomJsx.html)('input', {
classNames: 'new-todo',
placeholder: 'What needs to be done?',
value: model.editingTitle,
'on-keydown': (0, _helpers.bind)(onInput, handler) })
),
(0, _snabbdomJsx.html)(
'section',
{
classNames: 'main',
'style-display': model.tasks.length ? 'block' : 'none' },
(0, _snabbdomJsx.html)('input', {
classNames: 'toggle-all',
type: 'checkbox',
checked: remaining === 0,
'on-click': (0, _helpers.pipe)(targetChecked, Action.ToggleAll, handler) }),
(0, _snabbdomJsx.html)(
'ul',
{ classNames: 'todo-list' },
filtered.map(function (task) {
return (0, _snabbdomJsx.html)(TodoItem, { item: task, handler: handler });
})
)
),
(0, _snabbdomJsx.html)(
'footer',
{
classNames: 'footer',
'style-display': model.tasks.length ? 'block' : 'none' },
(0, _snabbdomJsx.html)(
'span',
{ classNames: 'todo-count' },
(0, _snabbdomJsx.html)(
'strong',
null,
remaining
),
' item',
remaining === 1 ? '' : 's',
' left'
),
(0, _snabbdomJsx.html)(
'ul',
{ classNames: 'filters' },
(0, _snabbdomJsx.html)(
'li',
null,
(0, _snabbdomJsx.html)(
'a',
{ href: '#/', 'class-selected': model.filter === 'all' },
'All'
)
),
(0, _snabbdomJsx.html)(
'li',
null,
(0, _snabbdomJsx.html)(
'a',
{ href: '#/active', 'class-selected': model.filter === 'active' },
'Active'
)
),
(0, _snabbdomJsx.html)(
'li',
null,
(0, _snabbdomJsx.html)(
'a',
{ href: '#/completed', 'class-selected': model.filter === 'completed' },
'Completed'
)
)
),
(0, _snabbdomJsx.html)(
'button',
{
classNames: 'clear-completed',
'on-click': (0, _helpers.bind)(handler, Action.Archive()) },
'Clear completed'
)
)
);
}
var TodoItem = function TodoItem(_ref2) {
var item = _ref2.item;
var handler = _ref2.handler;
return (0, _snabbdomJsx.html)(_task2['default'], {
model: item,
handler: function (action) {
return handler(Action.Modify(item.id, action));
},
onRemove: (0, _helpers.bind)(handler, Action.Remove(item.id)) });
};
function init() {
var tasks = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
return {
nextID: tasks.reduce(function (acc, task) {
return Math.max(acc, task.id);
}, 0) + 1,
tasks: tasks,
editingTitle: '',
filter: 'all'
};
}
function remainingTodos(tasks) {
return tasks.reduce(function (acc, task) {
return !task.done ? acc + 1 : acc;
}, 0);
}
function filteredTodos(tasks, filter) {
return filter === 'completed' ? tasks.filter(function (todo) {
return todo.done;
}) : filter === 'active' ? tasks.filter(function (todo) {
return !todo.done;
}) : tasks;
}
function addTodo(model, title) {
return _extends({}, model, {
tasks: [].concat(_toConsumableArray(model.tasks), [_task2['default'].init(model.nextID, title)]),
editingTitle: '',
nextID: model.nextID + 1
});
}
function removeTodo(model, id) {
return _extends({}, model, {
tasks: model.tasks.filter(function (taskModel) {
return taskModel.id !== id;
})
});
}
function archiveTodos(model, id) {
return _extends({}, model, {
tasks: model.tasks.filter(function (taskModel) {
return !taskModel.done;
})
});
}
function toggleAll(model, done) {
return _extends({}, model, {
tasks: model.tasks.map(function (taskModel) {
return _task2['default'].update(taskModel, task.Action.Toggle(done));
})
});
}
function modifyTodo(model, id, action) {
return _extends({}, model, {
tasks: model.tasks.map(function (taskModel) {
return taskModel.id !== id ? taskModel : _task2['default'].update(taskModel, action);
})
});
}
function update(model, action) {
return Action['case']({
Add: function Add(title) {
return addTodo(model, title);
},
Remove: function Remove(id) {
return removeTodo(model, id);
},
Archive: function Archive() {
return archiveTodos(model);
},
ToggleAll: function ToggleAll(done) {
return toggleAll(model, done);
},
Filter: function Filter(filter) {
return _extends({}, model, { filter: filter });
},
Modify: function Modify(id, action) {
return modifyTodo(model, id, action);
}
}, action);
}
exports['default'] = { view: view, init: init, update: update, Action: Action };
module.exports = exports['default'];
},{"../../../snabbdom-jsx":19,"./helpers":1,"./task":4,"union-type":18}],6:[function(require,module,exports){
},{"../arity":1}],6:[function(require,module,exports){
module.exports = {

@@ -625,4 +355,2 @@ array: Array.isArray,

var insertedVnodeQueue;
function sameVnode(vnode1, vnode2) {

@@ -658,3 +386,3 @@ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;

function createElm(vnode) {
function createElm(vnode, insertedVnodeQueue) {
var i, data = vnode.data;

@@ -679,3 +407,3 @@ if (isDef(data)) {

for (i = 0; i < children.length; ++i) {
elm.appendChild(createElm(children[i]));
elm.appendChild(createElm(children[i], insertedVnodeQueue));
}

@@ -697,5 +425,5 @@ } else if (is.primitive(vnode.text)) {

function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
function addVnodes(parentElm, before, vnodes, startIdx, endIdx, insertedVnodeQueue) {
for (; startIdx <= endIdx; ++startIdx) {
parentElm.insertBefore(createElm(vnodes[startIdx]), before);
parentElm.insertBefore(createElm(vnodes[startIdx], insertedVnodeQueue), before);
}

@@ -738,3 +466,3 @@ }

function updateChildren(parentElm, oldCh, newCh) {
function updateChildren(parentElm, oldCh, newCh, insertedVnodeQueue) {
var oldStartIdx = 0, newStartIdx = 0;

@@ -755,11 +483,11 @@ var oldEndIdx = oldCh.length - 1;

} else if (sameVnode(oldStartVnode, newStartVnode)) {
patchVnode(oldStartVnode, newStartVnode);
patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue);
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode)) {
patchVnode(oldEndVnode, newEndVnode);
patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue);
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
patchVnode(oldStartVnode, newEndVnode);
patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
parentElm.insertBefore(oldStartVnode.elm, oldEndVnode.elm.nextSibling);

@@ -769,3 +497,3 @@ oldStartVnode = oldCh[++oldStartIdx];

} else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
patchVnode(oldEndVnode, newStartVnode);
patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
parentElm.insertBefore(oldEndVnode.elm, oldStartVnode.elm);

@@ -778,7 +506,7 @@ oldEndVnode = oldCh[--oldEndIdx];

if (isUndef(idxInOld)) { // New element
parentElm.insertBefore(createElm(newStartVnode), oldStartVnode.elm);
parentElm.insertBefore(createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
patchVnode(elmToMove, newStartVnode);
patchVnode(elmToMove, newStartVnode, insertedVnodeQueue);
oldCh[idxInOld] = undefined;

@@ -792,3 +520,3 @@ parentElm.insertBefore(elmToMove.elm, oldStartVnode.elm);

before = isUndef(newCh[newEndIdx+1]) ? null : newCh[newEndIdx+1].elm;
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue);
} else if (newStartIdx > newEndIdx) {

@@ -799,3 +527,3 @@ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);

function patchVnode(oldVnode, vnode) {
function patchVnode(oldVnode, vnode, insertedVnodeQueue) {
var i, hook;

@@ -816,5 +544,5 @@ if (isDef(i = vnode.data) && isDef(hook = i.hook) && isDef(i = hook.prepatch)) {

if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(elm, oldCh, ch);
if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue);
} else if (isDef(ch)) {
addVnodes(elm, null, ch, 0, ch.length - 1);
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);
} else if (isDef(oldCh)) {

@@ -829,3 +557,2 @@ removeVnodes(elm, oldCh, 0, oldCh.length - 1);

}
return vnode;
}

@@ -835,14 +562,14 @@

var i;
insertedVnodeQueue = [];
var insertedVnodeQueue = [];
for (i = 0; i < cbs.pre.length; ++i) cbs.pre[i]();
if (oldVnode instanceof Element) {
if (oldVnode.parentElement !== null) {
createElm(vnode);
createElm(vnode, insertedVnodeQueue);
oldVnode.parentElement.replaceChild(vnode.elm, oldVnode);
} else {
oldVnode = emptyNodeAt(oldVnode);
patchVnode(oldVnode, vnode);
patchVnode(oldVnode, vnode, insertedVnodeQueue);
}
} else {
patchVnode(oldVnode, vnode);
patchVnode(oldVnode, vnode, insertedVnodeQueue);
}

@@ -852,3 +579,2 @@ for (i = 0; i < insertedVnodeQueue.length; ++i) {

}
insertedVnodeQueue = undefined;
for (i = 0; i < cbs.post.length; ++i) cbs.post[i]();

@@ -869,199 +595,2 @@ return vnode;

},{}],13:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
/**
* Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
* parameters. Unlike `nAry`, which passes only `n` arguments to the wrapped function,
* functions produced by `arity` will pass all provided arguments to the wrapped function.
*
* @func
* @memberOf R
* @sig (Number, (* -> *)) -> (* -> *)
* @category Function
* @param {Number} n The desired arity of the returned function.
* @param {Function} fn The function to wrap.
* @return {Function} A new function wrapping `fn`. The new function is
* guaranteed to be of arity `n`.
* @deprecated since v0.15.0
* @example
*
* var takesTwoArgs = function(a, b) {
* return [a, b];
* };
* takesTwoArgs.length; //=> 2
* takesTwoArgs(1, 2); //=> [1, 2]
*
* var takesOneArg = R.arity(1, takesTwoArgs);
* takesOneArg.length; //=> 1
* // All arguments are passed through to the wrapped function
* takesOneArg(1, 2); //=> [1, 2]
*/
module.exports = _curry2(function(n, fn) {
// jshint unused:vars
switch (n) {
case 0: return function() {return fn.apply(this, arguments);};
case 1: return function(a0) {return fn.apply(this, arguments);};
case 2: return function(a0, a1) {return fn.apply(this, arguments);};
case 3: return function(a0, a1, a2) {return fn.apply(this, arguments);};
case 4: return function(a0, a1, a2, a3) {return fn.apply(this, arguments);};
case 5: return function(a0, a1, a2, a3, a4) {return fn.apply(this, arguments);};
case 6: return function(a0, a1, a2, a3, a4, a5) {return fn.apply(this, arguments);};
case 7: return function(a0, a1, a2, a3, a4, a5, a6) {return fn.apply(this, arguments);};
case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) {return fn.apply(this, arguments);};
case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) {return fn.apply(this, arguments);};
case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {return fn.apply(this, arguments);};
default: throw new Error('First argument to arity must be a non-negative integer no greater than ten');
}
});
},{"./internal/_curry2":16}],14:[function(require,module,exports){
var _curry2 = require('./internal/_curry2');
var _curryN = require('./internal/_curryN');
var arity = require('./arity');
/**
* Returns a curried equivalent of the provided function, with the
* specified arity. The curried function has two unusual capabilities.
* First, its arguments needn't be provided one at a time. If `g` is
* `R.curryN(3, f)`, the following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value `R.__` may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is `R.__`,
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf R
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
* @param {Number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
* @see R.curry
* @example
*
* var addFourNumbers = function() {
* return R.sum([].slice.call(arguments, 0, 4));
* };
*
* var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*/
module.exports = _curry2(function curryN(length, fn) {
return arity(length, _curryN(length, [], fn));
});
},{"./arity":13,"./internal/_curry2":16,"./internal/_curryN":17}],15:[function(require,module,exports){
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0) {
return f1;
} else if (a != null && a['@@functional/placeholder'] === true) {
return f1;
} else {
return fn(a);
}
};
};
},{}],16:[function(require,module,exports){
var _curry1 = require('./_curry1');
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
var n = arguments.length;
if (n === 0) {
return f2;
} else if (n === 1 && a != null && a['@@functional/placeholder'] === true) {
return f2;
} else if (n === 1) {
return _curry1(function(b) { return fn(a, b); });
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true &&
b != null && b['@@functional/placeholder'] === true) {
return f2;
} else if (n === 2 && a != null && a['@@functional/placeholder'] === true) {
return _curry1(function(a) { return fn(a, b); });
} else if (n === 2 && b != null && b['@@functional/placeholder'] === true) {
return _curry1(function(b) { return fn(a, b); });
} else {
return fn(a, b);
}
};
};
},{"./_curry1":15}],17:[function(require,module,exports){
var arity = require('../arity');
/**
* Internal curryN function.
*
* @private
* @category Function
* @param {Number} length The arity of the curried function.
* @return {array} An array of arguments received thus far.
* @param {Function} fn The function to curry.
*/
module.exports = function _curryN(length, received, fn) {
return function() {
var combined = [];
var argsIdx = 0;
var left = length;
var combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
var result;
if (combinedIdx < received.length &&
(received[combinedIdx] == null ||
received[combinedIdx]['@@functional/placeholder'] !== true ||
argsIdx >= arguments.length)) {
result = received[combinedIdx];
} else {
result = arguments[argsIdx];
argsIdx += 1;
}
combined[combinedIdx] = result;
if (result == null || result['@@functional/placeholder'] !== true) {
left -= 1;
}
combinedIdx += 1;
}
return left <= 0 ? fn.apply(this, combined) : arity(left, _curryN(length, combined, fn));
};
};
},{"../arity":13}],18:[function(require,module,exports){
var curryN = require('ramda/src/curryN');

@@ -1136,22 +665,463 @@

},{"ramda/src/curryN":14}],19:[function(require,module,exports){
},{"ramda/src/curryN":2}],14:[function(require,module,exports){
"use strict";
var SVGNS = "http://www.w3.org/2000/svg";
var modulesNS = ['key', 'on', 'style', 'class', 'props'];
Object.defineProperty(exports, "__esModule", {
value: true
});
var KEY_ENTER = exports.KEY_ENTER = 13;
},{}],15:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isBoolean = isBoolean;
exports.bind = bind;
exports.pipe = pipe;
function isBoolean(arg) {
return typeof arg === 'boolean';
}
function bind(fn) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return function () {
for (var _len2 = arguments.length, args2 = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args2[_key2] = arguments[_key2];
}
return fn.apply(undefined, [].concat(args, args2));
};
};
function pipe() {
for (var _len3 = arguments.length, fns = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
fns[_key3] = arguments[_key3];
}
return function () {
var res = fns[0].apply(fns, arguments);
for (var i = 1; i < fns.length; i++) {
res = fns[i](res);
}
return res;
};
};
var targetChecked = exports.targetChecked = function targetChecked(e) {
return e.target.checked;
};
var targetValue = exports.targetValue = function targetValue(e) {
return e.target.value;
};
},{}],16:[function(require,module,exports){
'use strict';
var _snabbdomJsx = require('../../../snabbdom-jsx');
var _snabbdom = require('snabbdom');
var _snabbdom2 = _interopRequireDefault(_snabbdom);
var _todos = require('./todos');
var _todos2 = _interopRequireDefault(_todos);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var patch = _snabbdom2.default.init([require('snabbdom/modules/class'), // makes it easy to toggle classes
require('snabbdom/modules/props'), // for setting properties on DOM elements
require('snabbdom/modules/style'), // handles styling on elements with support for animations
require('snabbdom/modules/eventlisteners')]); /** @jsx html */
// attaches event listeners
var model = _todos2.default.init(handler),
vnode = document.getElementById('todoapp');
function updateUI() {
var newVnode = (0, _snabbdomJsx.html)(_todos2.default, { model: model, handler: handler });
vnode = patch(vnode, newVnode);
}
function handler(action) {
model = _todos2.default.update(model, action);
updateUI();
}
updateUI();
},{"../../../snabbdom-jsx":19,"./todos":18,"snabbdom":11,"snabbdom/modules/class":7,"snabbdom/modules/eventlisteners":8,"snabbdom/modules/props":9,"snabbdom/modules/style":10}],17:[function(require,module,exports){
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** @jsx html */
Object.defineProperty(exports, "__esModule", {
value: true
});
var _snabbdomJsx = require('../../../snabbdom-jsx');
var _unionType = require('union-type');
var _unionType2 = _interopRequireDefault(_unionType);
var _helpers = require('./helpers');
var _constants = require('./constants');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// model : {id: Number, title: String, done: Boolean, editing: Boolean, editingValue: String }
var Action = (0, _unionType2.default)({
SetTitle: [String],
Toggle: [_helpers.isBoolean],
StartEdit: [],
CommitEdit: [String],
CancelEdit: []
});
function onInput(handler, e) {
if (e.keyCode === _constants.KEY_ENTER) handler(Action.CommitEdit(e.target.value));
}
var view = function view(_ref) {
var model = _ref.model;
var handler = _ref.handler;
var onRemove = _ref.onRemove;
return (0, _snabbdomJsx.html)(
'li',
{
key: model.id,
'class-completed': !!model.done && !model.editing,
'class-editing': model.editing },
(0, _snabbdomJsx.html)(
'div',
{ selector: '.view' },
(0, _snabbdomJsx.html)('input', {
selector: '.toggle',
type: 'checkbox',
checked: !!model.done,
'on-click': (0, _helpers.pipe)(_helpers.targetChecked, Action.Toggle, handler) }),
(0, _snabbdomJsx.html)(
'label',
{
'on-dblclick': (0, _helpers.bind)(handler, Action.StartEdit()) },
model.title
),
(0, _snabbdomJsx.html)('button', {
selector: '.destroy',
'on-click': onRemove })
),
(0, _snabbdomJsx.html)('input', {
selector: '.edit',
value: model.title,
'on-blur': (0, _helpers.bind)(handler, Action.CancelEdit()),
'on-keydown': (0, _helpers.bind)(onInput, handler) })
);
};
function init(id, title) {
return { id: id, title: title, done: false, editing: false, editingValue: '' };
}
function update(task, action) {
return Action.case({
Toggle: function Toggle(done) {
return _extends({}, task, { done: done });
},
StartEdit: function StartEdit() {
return _extends({}, task, { editing: true, editingValue: task.title });
},
CommitEdit: function CommitEdit(title) {
return _extends({}, task, { title: title, editing: false, editingValue: '' });
},
CancelEdit: function CancelEdit(title) {
return _extends({}, task, { editing: false, editingValue: '' });
}
}, action);
}
exports.default = { view: view, init: init, update: update, Action: Action };
},{"../../../snabbdom-jsx":19,"./constants":14,"./helpers":15,"union-type":13}],18:[function(require,module,exports){
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** @jsx html */
Object.defineProperty(exports, "__esModule", {
value: true
});
var _snabbdomJsx = require('../../../snabbdom-jsx');
var _unionType = require('union-type');
var _unionType2 = _interopRequireDefault(_unionType);
var _helpers = require('./helpers');
var _constants = require('./constants');
var _task = require('./task');
var _task2 = _interopRequireDefault(_task);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
// model : { nextID: Number, editingTitle: String, tasks: [task.model], filter: String }
var Action = (0, _unionType2.default)({
Input: [String],
Add: [String],
Remove: [Number],
Archive: [],
ToggleAll: [_helpers.isBoolean],
Filter: [String],
Modify: [Number, _task2.default.Action]
});
function onInput(handler, e) {
if (e.keyCode === _constants.KEY_ENTER) {
handler(Action.Add(e.target.value));
}
}
function view(_ref) {
var model = _ref.model;
var handler = _ref.handler;
var remaining = remainingTodos(model.tasks);
var filtered = filteredTodos(model.tasks, model.filter);
return (0, _snabbdomJsx.html)(
'section',
{ selector: '.todoapp' },
(0, _snabbdomJsx.html)(
'header',
{ selector: '.header' },
(0, _snabbdomJsx.html)(
'h1',
null,
'todos'
),
(0, _snabbdomJsx.html)('input', {
selector: '.new-todo',
placeholder: 'What needs to be done?',
value: model.editingTitle,
'on-input': (0, _helpers.pipe)(_helpers.targetValue, Action.Input, handler),
'on-keydown': (0, _helpers.bind)(onInput, handler) })
),
(0, _snabbdomJsx.html)(
'section',
{
selector: '.main',
'style-display': model.tasks.length ? 'block' : 'none' },
(0, _snabbdomJsx.html)('input', {
selector: '.toggle-all',
type: 'checkbox',
checked: remaining === 0,
'on-click': (0, _helpers.pipe)(_helpers.targetChecked, Action.ToggleAll, handler) }),
(0, _snabbdomJsx.html)(
'ul',
{ selector: '.todo-list' },
filtered.map(function (task) {
return (0, _snabbdomJsx.html)(TodoItem, { item: task, handler: handler });
})
)
),
(0, _snabbdomJsx.html)(
'footer',
{
selector: '.footer',
'style-display': model.tasks.length ? 'block' : 'none' },
(0, _snabbdomJsx.html)(
'span',
{ classNames: 'todo-count' },
(0, _snabbdomJsx.html)(
'strong',
null,
remaining
),
' item',
remaining === 1 ? '' : 's',
' left'
),
(0, _snabbdomJsx.html)(
'ul',
{ selector: '.filters' },
(0, _snabbdomJsx.html)(
'li',
null,
(0, _snabbdomJsx.html)(
'a',
{ href: '#/', 'class-selected': model.filter === 'all' },
'All'
)
),
(0, _snabbdomJsx.html)(
'li',
null,
(0, _snabbdomJsx.html)(
'a',
{ href: '#/active', 'class-selected': model.filter === 'active' },
'Active'
)
),
(0, _snabbdomJsx.html)(
'li',
null,
(0, _snabbdomJsx.html)(
'a',
{ href: '#/completed', 'class-selected': model.filter === 'completed' },
'Completed'
)
)
),
(0, _snabbdomJsx.html)(
'button',
{
classNames: 'clear-completed',
'on-click': (0, _helpers.bind)(handler, Action.Archive()) },
'Clear completed'
)
)
);
}
var TodoItem = function TodoItem(_ref2) {
var item = _ref2.item;
var _handler = _ref2.handler;
return (0, _snabbdomJsx.html)(_task2.default, {
model: item,
handler: function handler(action) {
return _handler(Action.Modify(item.id, action));
},
onRemove: (0, _helpers.bind)(_handler, Action.Remove(item.id)) });
};
function init(handler) {
window.addEventListener('hashchange', function (_) {
return handler(Action.Filter(window.location.hash.substr(2) || 'all'));
});
return {
nextID: 1,
tasks: [],
editingTitle: '',
filter: 'all'
};
}
function remainingTodos(tasks) {
return tasks.reduce(function (acc, task) {
return !task.done ? acc + 1 : acc;
}, 0);
}
function filteredTodos(tasks, filter) {
return filter === 'completed' ? tasks.filter(function (todo) {
return todo.done;
}) : filter === 'active' ? tasks.filter(function (todo) {
return !todo.done;
}) : tasks;
}
function addTodo(model, title) {
return _extends({}, model, {
tasks: [].concat(_toConsumableArray(model.tasks), [_task2.default.init(model.nextID, title)]),
editingTitle: '',
nextID: model.nextID + 1
});
}
function removeTodo(model, id) {
return _extends({}, model, {
tasks: model.tasks.filter(function (taskModel) {
return taskModel.id !== id;
})
});
}
function archiveTodos(model, id) {
return _extends({}, model, {
tasks: model.tasks.filter(function (taskModel) {
return !taskModel.done;
})
});
}
function toggleAll(model, done) {
return _extends({}, model, {
tasks: model.tasks.map(function (taskModel) {
return _task2.default.update(taskModel, _task2.default.Action.Toggle(done));
})
});
}
function modifyTodo(model, id, action) {
return _extends({}, model, {
tasks: model.tasks.map(function (taskModel) {
return taskModel.id !== id ? taskModel : _task2.default.update(taskModel, action);
})
});
}
function update(model, action) {
return Action.case({
Input: function Input(editingTitle) {
return _extends({}, model, { editingTitle: editingTitle });
},
Add: function Add(title) {
return addTodo(model, title);
},
Remove: function Remove(id) {
return removeTodo(model, id);
},
Archive: function Archive() {
return archiveTodos(model);
},
ToggleAll: function ToggleAll(done) {
return toggleAll(model, done);
},
Filter: function Filter(filter) {
return _extends({}, model, { filter: filter });
},
Modify: function Modify(id, action) {
return modifyTodo(model, id, action);
}
}, action);
}
exports.default = { view: view, init: init, update: update, Action: Action };
},{"../../../snabbdom-jsx":19,"./constants":14,"./helpers":15,"./task":17,"union-type":13}],19:[function(require,module,exports){
"use strict";
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
var SVGNS = 'http://www.w3.org/2000/svg';
var modulesNS = ['hook', 'on', 'style', 'class', 'props', 'attrs'];
var slice = Array.prototype.slice;
function isPrimitive(val) {
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || typeof val === 'symbol' || val === null || val === undefined;
return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'symbol' || val === null || val === undefined;
}
function normalizeAttrs(attrs, ns) {
var map = { ns: ns };
for (var i = 0, len = modulesNS.length; i < len; i++) {
var modNS = modulesNS[i];
if (attrs[modNS]) map[modNS] = attrs[modNS];
function normalizeAttrs(attrs, nsURI, defNS, modules) {
var map = { ns: nsURI };
for (var i = 0, len = modules.length; i < len; i++) {
var mod = modules[i];
if (attrs[mod]) map[mod] = attrs[mod];
}
for (var key in attrs) {
var parts = key.split('-');
if (parts.length > 1) addAttr(parts[0], parts[1], attrs[key]);else if (!map[key]) addAttr('props', parts[0], attrs[key]);
if (key !== 'key' && key !== 'classNames' && key !== 'selector') {
var idx = key.indexOf('-');
if (idx > 0) addAttr(key.slice(0, idx), key.slice(idx + 1), attrs[key]);else if (!map[key]) addAttr(defNS, key, attrs[key]);
}
}

@@ -1166,4 +1136,7 @@ return map;

function jsx(ns, modules, tag, attrs, children) {
attrs = attrs || {};
function buildFromStringTag(nsURI, defNS, modules, tag, attrs, children) {
if (attrs.selector) {
tag = tag + attrs.selector;
}
if (attrs.classNames) {

@@ -1173,15 +1146,33 @@ var cns = attrs.classNames;

}
if (typeof tag === 'string') return {
return {
sel: tag,
data: normalizeAttrs(attrs, ns),
data: normalizeAttrs(attrs, nsURI, defNS, modules),
children: children.map(function (c) {
return isPrimitive(c) ? { text: c } : c;
})
};else if (typeof tag === 'function') return tag(attrs, children);else if (tag && typeof tag.view === 'function') return tag.view(attrs, children);
}),
key: attrs.key
};
}
function JSX(ns, modules) {
function buildFromComponent(nsURI, defNS, modules, tag, attrs, children) {
var res;
if (typeof tag === 'function') res = tag(attrs, children);else if (tag && typeof tag.view === 'function') res = tag.view(attrs, children);else if (tag && typeof tag.render === 'function') res = tag.render(attrs, children);else throw "JSX tag must be either a string, a function or an object with 'view' or 'render' methods";
res.key = attrs.key;
return res;
}
function buildVnode(nsURI, defNS, modules, tag, attrs, children) {
attrs = attrs || {};
if (typeof tag === 'string') {
return buildFromStringTag(nsURI, defNS, modules, tag, attrs, children);
} else {
return buildFromComponent(nsURI, defNS, modules, tag, attrs, children);
}
}
function JSX(nsURI, defNS, modules) {
return function jsxWithCustomNS(tag, attrs, children) {
if (arguments.length > 3 || !Array.isArray(children)) children = slice.call(arguments, 2);
return jsx(ns, modules || modulesNS, tag, attrs, children);
return buildVnode(nsURI, defNS || 'props', modules || modulesNS, tag, attrs, children);
};

@@ -1192,6 +1183,6 @@ }

html: JSX(undefined),
svg: JSX(SVGNS),
svg: JSX(SVGNS, 'attrs'),
JSX: JSX
};
},{}]},{},[2]);
},{}]},{},[16]);

@@ -21,1 +21,4 @@

};
export const targetChecked = e => e.target.checked;
export const targetValue = e => e.target.value;

@@ -0,1 +1,4 @@

/** @jsx html */
import { html } from '../../../snabbdom-jsx';
import snabbdom from 'snabbdom';

@@ -9,23 +12,18 @@ import Todos from './todos';

require('snabbdom/modules/eventlisteners'), // attaches event listeners
require('./snabbdom-modules/window-events') // attaches event listeners to windows
]);
let model = Todos.init(handler),
vnode = document.getElementById('todoapp');
function updateUI() {
const newVnode = <Todos model={model} handler={handler} />
vnode = patch(vnode, newVnode);
}
function main(initState, oldVnode, {view, update}) {
const newVnode = view({
model : initState,
handler : e => {
const newState = update(initState, e);
main(newState, newVnode, {view, update});
}
});
patch(oldVnode, newVnode);
function handler(action) {
model = Todos.update(model, action);
updateUI();
}
main(
Todos.init(), // the initial state
document.getElementById('todoapp'),
Todos
);
updateUI();

@@ -5,6 +5,5 @@ /** @jsx html */

import Type from 'union-type';
import { bind, pipe, isBoolean } from './helpers';
import { bind, pipe, isBoolean, targetValue, targetChecked } from './helpers';
import { KEY_ENTER } from './constants';
const KEY_ENTER = 13;
// model : {id: Number, title: String, done: Boolean, editing: Boolean, editingValue: String }

@@ -19,5 +18,4 @@ const Action = Type({

const targetChecked = e => e.target.checked;
const targetValue = e => e.target.value;
function onInput(handler, e) {

@@ -33,20 +31,20 @@ if(e.keyCode === KEY_ENTER)

class-editing={model.editing}>
<div classNames="view">
<input
classNames="toggle"
<div selector=".view">
<input
selector=".toggle"
type="checkbox"
checked={!!model.done}
on-click={ pipe(targetChecked, Action.Toggle, handler) } />
<label
on-dblclick={ bind(handler, Action.StartEdit()) }>{model.title}</label>
<button
classNames="destroy"
selector=".destroy"
on-click={onRemove} />
</div>
<input
classNames="edit"
selector=".edit"
value={model.title}

@@ -53,0 +51,0 @@ on-blur={ bind(handler, Action.CancelEdit()) }

@@ -5,9 +5,9 @@ /** @jsx html */

import Type from 'union-type';
import { bind, pipe, isBoolean } from './helpers';
import { bind, pipe, isBoolean, targetValue, targetChecked } from './helpers';
import { KEY_ENTER } from './constants';
import Task from './task';
const KEY_ENTER = 13;
// model : { nextID: Number, editingTitle: String, tasks: [task.model], filter: String }
const Action = Type({
Input : [String],
Add : [String],

@@ -21,5 +21,2 @@ Remove : [Number],

const targetChecked = e => e.target.checked;
const targetValue = e => e.target.value;
function onInput(handler, e) {

@@ -29,46 +26,43 @@ if(e.keyCode === KEY_ENTER) {

}
}
function view({model, handler}) {
const remaining = remainingTodos(model.tasks);
const filtered = filteredTodos(model.tasks, model.filter);
return <section
classNames="todoapp"
windowOn-hashchange={ _ => handler(Action.Filter(window.location.hash.substr(2) || 'all')) }>
<header classNames="header" >
return <section selector=".todoapp">
<header selector=".header" >
<h1>todos</h1>
<input
classNames="new-todo"
selector=".new-todo"
placeholder="What needs to be done?"
value={model.editingTitle}
on-keydown={ bind(onInput, handler) } />
on-input={pipe(targetValue, Action.Input, handler)}
on-keydown={bind(onInput, handler)} />
</header>
<section
classNames="main"
selector=".main"
style-display={ model.tasks.length ? 'block' : 'none' }>
<input
classNames="toggle-all"
selector=".toggle-all"
type="checkbox"
checked={ remaining === 0 }
on-click={ pipe(targetChecked, Action.ToggleAll, handler) } />
<ul classNames="todo-list">
<ul selector=".todo-list">
{ filtered.map( task => <TodoItem item={task} handler={handler} /> ) }
</ul>
</section>
<footer
classNames="footer"
selector=".footer"
style-display={ model.tasks.length ? 'block' : 'none' }>
<span classNames="todo-count">
<strong>{remaining}</strong> item{remaining === 1 ? '' : 's'} left
</span>
<ul classNames="filters">
<ul selector=".filters">
<li><a href="#/" class-selected={model.filter === 'all'}>All</a></li>

@@ -82,5 +76,5 @@ <li><a href="#/active" class-selected={model.filter === 'active'}>Active</a></li>

</footer>
</section>
}

@@ -95,9 +89,12 @@

function init(tasks=[]) {
return {
nextID: tasks.reduce((acc, task) => Math.max(acc, task.id), 0) + 1,
tasks,
editingTitle: '',
filter: 'all'
}
function init(handler) {
window.addEventListener('hashchange',
_ => handler(Action.Filter(window.location.hash.substr(2) || 'all')));
return {
nextID: 1,
tasks: [],
editingTitle: '',
filter: 'all'
};
}

@@ -117,3 +114,3 @@

return {...model,
tasks : [ ...model.tasks,
tasks : [ ...model.tasks,
Task.init(model.nextID, title)],

@@ -139,3 +136,3 @@ editingTitle : '',

return {...model,
tasks : model.tasks.map( taskModel => Task.update(taskModel, task.Action.Toggle(done)) )
tasks : model.tasks.map( taskModel => Task.update(taskModel, Task.Action.Toggle(done)) )
};

@@ -155,2 +152,3 @@ }

return Action.case({
Input : editingTitle => ({...model, editingTitle}),
Add : title => addTodo(model, title),

@@ -165,2 +163,2 @@ Remove : id => removeTodo(model, id),

export default { view, init, update, Action }
export default { view, init, update, Action }
{
"name": "snabbdom-jsx",
"version": "0.2.0",
"version": "0.3.0",
"description": "Write snabbdom views using JSX and Babel",
"main": "snabbdom-jsx.js",
"scripts": {
"test": "babel-node test.js"
"test": "babel-node test.js | tap-spec"
},

@@ -26,9 +26,8 @@ "repository": {

"babel-cli": "^6.1.18",
"babel-plugin-syntax-jsx": "^6.0.14",
"babel-plugin-transform-es2015-destructuring": "^6.0.18",
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.3",
"babel-plugin-transform-es2015-parameters": "^6.0.18",
"babel-plugin-transform-react-jsx": "^6.0.18",
"babel-preset-es2015": "^6.1.2",
"babel-preset-react": "^6.1.2",
"babel-preset-stage-2": "^6.1.2",
"tap-spec": "^4.1.0",
"tape": "^4.0.3"
}
}

@@ -1,6 +0,15 @@

Write [Snabbdom](https://github.com/paldepind/snabbdom) virtual DOM with [Babel's JSX](http://babeljs.io/docs/advanced/transformers/other/react/).
Write [Snabbdom](https://github.com/paldepind/snabbdom) virtual DOM with
[Babel's JSX](http://babeljs.io/docs/advanced/transformers/other/react/).
Snabbdom is a small Virtual DOM library. Unlike React, it's not a fully opinionated framework, but just focuses on the core virtual DOM problem : construct virtual DOM trees (virtual nodes) and patch the real DOM with them. When those operations happen is entirely up to you. The main benefit is that you can adopt whatver architdectural UI pattern you like in your application.
Snabbdom is a small Virtual DOM library. Unlike React, it's not a full View
framework, it just focuses on the core virtual DOM problem : construct virtual DOM
trees (virtual nodes) and patch the real DOM with them. it's entirely up to you
to decide when those operations will happen. The main benefit is that you can adopt
whatever architectural UI pattern you like in your application.
Babel is JavaScript compiler that converts ES2015 (modern JavaScript) into compatible JavaScript (ES5) code. A nice feature of Babel is that it supports [React JSX syntax](http://facebook.github.io/react/docs/displaying-data.html#jsx-syntax) and in the same time allows you to take the result of this JSX (attributes + body) and do wharever you like with it. Snabbdom-jsx transforms this JSX data into snabbdom virtual nodes.
Babel is a JavaScript compiler that converts modern JavaScript (ES2015 and beyond)
into compatible JavaScript (ES5) code. A nice feature of Babel is that it supports
[React JSX syntax](http://facebook.github.io/react/docs/displaying-data.html#jsx-syntax) and
in the same time allows you to take the result of this JSX (attributes + body) and do
whatever you like with it. Snabbdom-jsx transforms this JSX data into Snabbdom virtual nodes.

@@ -36,3 +45,5 @@ Features:

The `/** @jsx html */` pragma at the top tells Babel to use the `html` function instead of the React.createElement default. The `html` function takes arguments passed from Babel and generates virtual nodes as expected by Snabbdom's `patch` function.
The `/** @jsx html */` pragma at the top tells Babel to use the `html` function instead
of the React.createElement default. The `html` function takes arguments passed from Babel
and generates virtual nodes as expected by Snabbdom's `patch` function.

@@ -42,3 +53,4 @@ Mapping JSX attributes

A quick remainder: in snabbdom, most of the functionalities like toggling classes, styles and setting properties on DOM elements are delegated to separate modules.
A quick remainder: in snabbdom, most of the functionalities like toggling classes, styles
and setting properties on DOM elements are delegated to separate modules.

@@ -56,3 +68,5 @@ For example

Each module handles a portion of the data attributes (the 2nd parameter to `h`). And each portion is stored inside a *namespace*, for example, event attributes are placed inside the `on` namespace, class attributes inside the `class` namespace and so on.
Each module handles a portion of the data attributes (the 2nd parameter to `h`). And
each portion is stored inside a *namespace*, for example, event attributes are placed
inside the `on` namespace, class attributes inside the `class` namespace and so on.

@@ -83,3 +97,7 @@

This is a generic rule to map a JSX attribute to a specific module, you need to prefix the attribute with `pref-` where `pref` is the namespace used by the module in Snabbdom. As in the example above, all attributes with the `on-` prefix (i.e. event listeners) will be placed inside the the `on` namespace. This gives us a simple and extensible pattern to support other custom modules.
This is a generic rule to map a JSX attribute to a specific module, you need to prefix
the attribute with `pref-` where `pref` is the namespace used by the module in Snabbdom.
As in the example above, all attributes with the `on-` prefix (i.e. event listeners) will
be placed inside the the `on` namespace. This gives us a simple and extensible pattern to
support other custom modules.

@@ -104,3 +122,4 @@ Another example using the `class` namespace

But you can also specify an unique object the same way as in the `h` function, this is useful when you have a dynamic object
But you can also specify an unique object the same way as in the `h` function, this is
useful when you have a dynamic object

@@ -133,4 +152,4 @@ ```js

Static classes
==============
Id Static classes (sel attribute)
================================

@@ -140,22 +159,33 @@ In Snabbdom you can create an element using a css-like syntax

```js
h('div.class1.class2', ...)
h('div#id.class1.class2', ...)
```
This will add the class names to the classList of the element. Unlike classes specified in the `class` namesapce, those are static classes meaning they will not be re-updated during patch operations.
This will set the element id add the class names to its classList property. Unlike
classes specified in the `class` namespace, those are static classes meaning they
will not be re-updated during patch operations.
In JSX you can use the `classNames` attribute to create static classes
In JSX you can use the `selector` attribute to set the element's id and add static classes
```js
<div selector="#id.class1.class2" />
```
You can also specify static classes via the `classNames` property
```js
<div classNames="class1 class 2" />
<div classNames="class1 class2" />
```
You can also use an array instead of a string
You can also provide an array to `classNames` instead of a string
```js
const classes = ['classe1', ...];
const classes = ['class1', 'class2'];
<div classNames={classes} />
```
it's important to remember to not pass dynamic values to `selector` or `classNames`.
As this can lead to some unexpected issues. If you want to set dynamic classes, use
the class module instead.
JSX Components

@@ -176,3 +206,4 @@ ===============

Instead of classes, Snabbdom-jsx components are simple functions of type `(attributes, children) => vnode`.
Instead of classes, Snabbdom-jsx components are simple functions of type
`(attributes, children) => vnode`.

@@ -190,5 +221,10 @@ ```js

As in React, note that all components must start with a capital letter, while regular HTML tags start with lower case letters. This the way Babel also distinguish component invocation from simple tag creation.
As in React, note that all components must start with a capital letter, while regular
HTML tags start with lower case letters. This the way Babel also distinguish component
invocation from simple tag creation.
Perhaps of less obvious utility, but instead of a function, a component can also be an object with a `view` or `render` function; i added this in order to support nesting in UI patterns; especially in the Elm architecture, where a component is an object with a `view` (or `render`) function (among others)
Perhaps of less obvious utility, but instead of a function, a component can also be an
object with a `view` or `render` function. I added this in order to support nesting in
UI patterns; especially in the Elm architecture, where a component is an object with a
`view` (or `render`) function (among others)

@@ -208,14 +244,15 @@ for example you can have a `Task` component

Todos.view = ({todos}) => todos.map(todo =>
<Task todo={todo} key={todo.id} />)
Todos.view = ({todos}) =>
todos.map( task => <Task task={task} /> )
```
You can also add a `key` attribute directly to a Component. It will be copied inside the resulting vnode
As illustrated above, you can also add a `key` attribute directly to a Component.
It will be copied inside the resulting vnode
```js
Todos.view = ({todos}) =>
todos.map( task => <Task key={task.id} task={task} /> )
```
If you're wondering how Components would fit in a large application, you can look into the [todomvc example](https://github.com/yelouafi/snabbdom-jsx/tree/master/examples/todomvc). The application is implemented using the Elm architecture. For more information see [React-less Virtual DOM with Snabbdom : functions everywhere!](https://medium.com/@yelouafi/react-less-virtual-dom-with-snabbdom-functions-everywhere-53b672cb2fe3)
If you're wondering how Components would fit in a large application, you can look into
the [todomvc example](https://github.com/yelouafi/snabbdom-jsx/tree/master/examples/todomvc).
The application is implemented using the Elm architecture. For more information see
[React-less Virtual DOM with Snabbdom : functions everywhere!](https://medium.com/@yelouafi/react-less-virtual-dom-with-snabbdom-functions-everywhere-53b672cb2fe3)
"use strict";
var SVGNS = "http://www.w3.org/2000/svg";
var modulesNS = ['hook', 'on', 'style', 'class', 'props'];
var SVGNS = 'http://www.w3.org/2000/svg';
var modulesNS = ['hook', 'on', 'style', 'class', 'props', 'attrs'];
var slice = Array.prototype.slice;

@@ -24,7 +24,9 @@

for(var key in attrs) {
var idx = key.indexOf('-');
if(idx > 0)
addAttr(key.slice(0, idx), key.slice(idx+1), attrs[key]);
else if(!map[key])
addAttr(defNS, key, attrs[key]);
if(key !== 'key' && key !== 'classNames' && key !== 'selector') {
var idx = key.indexOf('-');
if(idx > 0)
addAttr(key.slice(0, idx), key.slice(idx+1), attrs[key]);
else if(!map[key])
addAttr(defNS, key, attrs[key]);
}
}

@@ -34,11 +36,12 @@ return map;

function addAttr(namespace, key, val) {
if(key !== 'key') {
var ns = map[namespace] || (map[namespace] = {});
ns[key] = val;
}
var ns = map[namespace] || (map[namespace] = {});
ns[key] = val;
}
}
function buildVnode(nsURI, defNS, modules, tag, attrs, children) {
attrs = attrs || {};
function buildFromStringTag(nsURI, defNS, modules, tag, attrs, children) {
if(attrs.selector) {
tag = tag + attrs.selector;
}
if(attrs.classNames) {

@@ -51,23 +54,32 @@ var cns = attrs.classNames;

return {
sel : tag,
data : normalizeAttrs(attrs, nsURI, defNS, modules),
children : children.map( function(c) {
return isPrimitive(c) ? {text: c} : c;
}),
key: attrs.key
};
}
function buildFromComponent(nsURI, defNS, modules, tag, attrs, children) {
var res;
if(typeof tag === 'function')
res = tag(attrs, children);
else if(tag && typeof tag.view === 'function')
res = tag.view(attrs, children);
else if(tag && typeof tag.render === 'function')
res = tag.render(attrs, children);
else
throw "JSX tag must be either a string, a function or an object with 'view' or 'render' methods";
res.key = attrs.key;
return res;
}
function buildVnode(nsURI, defNS, modules, tag, attrs, children) {
attrs = attrs || {};
if(typeof tag === 'string') {
return {
sel : tag,
data : normalizeAttrs(attrs, nsURI, defNS, modules),
children : children.map( function(c) {
return isPrimitive(c) ? {text: c} : c;
}),
key: attrs.key
};
return buildFromStringTag(nsURI, defNS, modules, tag, attrs, children)
} else {
var res;
if(typeof tag === 'function')
res = tag(attrs, children);
else if(tag && typeof tag.view === 'function')
res = tag.view(attrs, children);
else if(tag && typeof tag.render === 'function')
res = tag.view(attrs, children);
else
throw "JSX tag must be either a string, a function or an object with 'view' or 'render' methods";
res.key = attrs.key;
return res;
return buildFromComponent(nsURI, defNS, modules, tag, attrs, children)
}

@@ -74,0 +86,0 @@ }

@@ -53,2 +53,13 @@ /** @jsx html */

const div3 = <div selector="#id.c1.c2"></div>;
assert.deepEqual(div3, {
sel: 'div#id.c1.c2',
data: {
ns: undefined
},
children: [],
key: undefined
});
assert.end();

@@ -55,0 +66,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc