Oops, back to Mithril 0.2.3!

This commit is contained in:
Toby Zerner 2016-03-21 21:25:00 +10:30
parent b62e25218a
commit 0c624f6c45
3 changed files with 74 additions and 56 deletions

View File

@ -573,7 +573,7 @@ exports.System = System;
"use strict" "use strict"
m.version = function () { m.version = function () {
return "v0.2.2-rc.1" return "v0.2.3"
} }
var hasOwn = {}.hasOwnProperty var hasOwn = {}.hasOwnProperty
@ -597,9 +597,24 @@ exports.System = System;
function noop() {} function noop() {}
/* eslint-disable max-len */ var voidElements = {
var voidElements = /^(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR)$/ AREA: 1,
/* eslint-enable max-len */ BASE: 1,
BR: 1,
COL: 1,
COMMAND: 1,
EMBED: 1,
HR: 1,
IMG: 1,
INPUT: 1,
KEYGEN: 1,
LINK: 1,
META: 1,
PARAM: 1,
SOURCE: 1,
TRACK: 1,
WBR: 1
}
// caching commonly used variables // caching commonly used variables
var $document, $location, $requestAnimationFrame, $cancelAnimationFrame var $document, $location, $requestAnimationFrame, $cancelAnimationFrame
@ -685,9 +700,7 @@ exports.System = System;
* or splat (optional) * or splat (optional)
*/ */
function m(tag, pairs) { function m(tag, pairs) {
for (var args = [], i = 1; i < arguments.length; i++) { var args = [].slice.call(arguments, 1)
args[i - 1] = arguments[i]
}
if (isObject(tag)) return parameterize(tag, args) if (isObject(tag)) return parameterize(tag, args)
@ -1015,7 +1028,7 @@ exports.System = System;
nodes = injectHTML(parentElement, index, data) nodes = injectHTML(parentElement, index, data)
} else { } else {
nodes = [$document.createTextNode(data)] nodes = [$document.createTextNode(data)]
if (!parentElement.nodeName.match(voidElements)) { if (!(parentElement.nodeName in voidElements)) {
insertNode(parentElement, nodes[0], index) insertNode(parentElement, nodes[0], index)
} }
} }
@ -1295,7 +1308,7 @@ exports.System = System;
var unloaders = [] var unloaders = []
function updateLists(views, controllers, view, controller) { function updateLists(views, controllers, view, controller) {
if (controller.onunload != null) { if (controller.onunload != null && unloaders.map(function(u) {return u.handler}).indexOf(controller.onunload) < 0) {
unloaders.push({ unloaders.push({
controller: controller, controller: controller,
handler: controller.onunload handler: controller.onunload
@ -1529,13 +1542,13 @@ exports.System = System;
} }
} }
function shouldUseSetAttribute(attrName) { var shouldUseSetAttribute = {
return attrName !== "list" && list: 1,
attrName !== "style" && style: 1,
attrName !== "form" && form: 1,
attrName !== "type" && type: 1,
attrName !== "width" && width: 1,
attrName !== "height" height: 1
} }
function setSingleAttr( function setSingleAttr(
@ -1566,7 +1579,7 @@ exports.System = System;
attrName === "className" ? "class" : attrName, attrName === "className" ? "class" : attrName,
dataAttr) dataAttr)
} }
} else if (attrName in node && shouldUseSetAttribute(attrName)) { } else if (attrName in node && !shouldUseSetAttribute[attrName]) {
// handle cases that are properties (but ignore cases where we // handle cases that are properties (but ignore cases where we
// should use setAttribute instead) // should use setAttribute instead)
// //
@ -1857,9 +1870,7 @@ exports.System = System;
} }
m.component = function (component) { m.component = function (component) {
for (var args = [], i = 1; i < arguments.length; i++) { var args = [].slice.call(arguments, 1)
args.push(arguments[i])
}
return parameterize(component, args) return parameterize(component, args)
} }
@ -2461,7 +2472,7 @@ exports.System = System;
m.deferred.onerror = function (e) { m.deferred.onerror = function (e) {
if (type.call(e) === "[object Error]" && if (type.call(e) === "[object Error]" &&
!e.constructor.toString().match(/ Error/)) { !/ Error/.test(e.constructor.toString())) {
pendingRequests = 0 pendingRequests = 0
throw e throw e
} }
@ -2607,16 +2618,14 @@ exports.System = System;
} }
function parameterizeUrl(url, data) { function parameterizeUrl(url, data) {
var tokens = url.match(/:[a-z]\w+/gi) if (data) {
url = url.replace(/:[a-z]\w+/gi, function(token){
if (tokens && data) {
forEach(tokens, function (token) {
var key = token.slice(1) var key = token.slice(1)
url = url.replace(token, data[key]) var value = data[key]
delete data[key] delete data[key]
return value
}) })
} }
return url return url
} }

View File

@ -7,10 +7,10 @@
"spin.js": "~2.0.1", "spin.js": "~2.0.1",
"moment": "~2.8.4", "moment": "~2.8.4",
"color-thief": "v2.0", "color-thief": "v2.0",
"mithril": "lhorie/mithril.js#next", "mithril": "lhorie/mithril.js#v0.2.3",
"es6-micro-loader": "caridy/es6-micro-loader#v0.2.1", "es6-micro-loader": "caridy/es6-micro-loader#v0.2.1",
"fastclick": "~1.0.6", "fastclick": "~1.0.6",
"autolink": "*", "autolink": "~1.0.0",
"m.attrs.bidi": "tobscure/m.attrs.bidi" "m.attrs.bidi": "tobscure/m.attrs.bidi"
} }
} }

View File

@ -573,7 +573,7 @@ exports.System = System;
"use strict" "use strict"
m.version = function () { m.version = function () {
return "v0.2.2-rc.1" return "v0.2.3"
} }
var hasOwn = {}.hasOwnProperty var hasOwn = {}.hasOwnProperty
@ -597,9 +597,24 @@ exports.System = System;
function noop() {} function noop() {}
/* eslint-disable max-len */ var voidElements = {
var voidElements = /^(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR)$/ AREA: 1,
/* eslint-enable max-len */ BASE: 1,
BR: 1,
COL: 1,
COMMAND: 1,
EMBED: 1,
HR: 1,
IMG: 1,
INPUT: 1,
KEYGEN: 1,
LINK: 1,
META: 1,
PARAM: 1,
SOURCE: 1,
TRACK: 1,
WBR: 1
}
// caching commonly used variables // caching commonly used variables
var $document, $location, $requestAnimationFrame, $cancelAnimationFrame var $document, $location, $requestAnimationFrame, $cancelAnimationFrame
@ -685,9 +700,7 @@ exports.System = System;
* or splat (optional) * or splat (optional)
*/ */
function m(tag, pairs) { function m(tag, pairs) {
for (var args = [], i = 1; i < arguments.length; i++) { var args = [].slice.call(arguments, 1)
args[i - 1] = arguments[i]
}
if (isObject(tag)) return parameterize(tag, args) if (isObject(tag)) return parameterize(tag, args)
@ -1015,7 +1028,7 @@ exports.System = System;
nodes = injectHTML(parentElement, index, data) nodes = injectHTML(parentElement, index, data)
} else { } else {
nodes = [$document.createTextNode(data)] nodes = [$document.createTextNode(data)]
if (!parentElement.nodeName.match(voidElements)) { if (!(parentElement.nodeName in voidElements)) {
insertNode(parentElement, nodes[0], index) insertNode(parentElement, nodes[0], index)
} }
} }
@ -1295,7 +1308,7 @@ exports.System = System;
var unloaders = [] var unloaders = []
function updateLists(views, controllers, view, controller) { function updateLists(views, controllers, view, controller) {
if (controller.onunload != null) { if (controller.onunload != null && unloaders.map(function(u) {return u.handler}).indexOf(controller.onunload) < 0) {
unloaders.push({ unloaders.push({
controller: controller, controller: controller,
handler: controller.onunload handler: controller.onunload
@ -1529,13 +1542,13 @@ exports.System = System;
} }
} }
function shouldUseSetAttribute(attrName) { var shouldUseSetAttribute = {
return attrName !== "list" && list: 1,
attrName !== "style" && style: 1,
attrName !== "form" && form: 1,
attrName !== "type" && type: 1,
attrName !== "width" && width: 1,
attrName !== "height" height: 1
} }
function setSingleAttr( function setSingleAttr(
@ -1566,7 +1579,7 @@ exports.System = System;
attrName === "className" ? "class" : attrName, attrName === "className" ? "class" : attrName,
dataAttr) dataAttr)
} }
} else if (attrName in node && shouldUseSetAttribute(attrName)) { } else if (attrName in node && !shouldUseSetAttribute[attrName]) {
// handle cases that are properties (but ignore cases where we // handle cases that are properties (but ignore cases where we
// should use setAttribute instead) // should use setAttribute instead)
// //
@ -1857,9 +1870,7 @@ exports.System = System;
} }
m.component = function (component) { m.component = function (component) {
for (var args = [], i = 1; i < arguments.length; i++) { var args = [].slice.call(arguments, 1)
args.push(arguments[i])
}
return parameterize(component, args) return parameterize(component, args)
} }
@ -2461,7 +2472,7 @@ exports.System = System;
m.deferred.onerror = function (e) { m.deferred.onerror = function (e) {
if (type.call(e) === "[object Error]" && if (type.call(e) === "[object Error]" &&
!e.constructor.toString().match(/ Error/)) { !/ Error/.test(e.constructor.toString())) {
pendingRequests = 0 pendingRequests = 0
throw e throw e
} }
@ -2607,16 +2618,14 @@ exports.System = System;
} }
function parameterizeUrl(url, data) { function parameterizeUrl(url, data) {
var tokens = url.match(/:[a-z]\w+/gi) if (data) {
url = url.replace(/:[a-z]\w+/gi, function(token){
if (tokens && data) {
forEach(tokens, function (token) {
var key = token.slice(1) var key = token.slice(1)
url = url.replace(token, data[key]) var value = data[key]
delete data[key] delete data[key]
return value
}) })
} }
return url return url
} }