Make linter happy with Mithril.js
This commit is contained in:
parent
f17658e2d3
commit
9d02042d78
2 changed files with 115 additions and 77 deletions
|
|
@ -89,9 +89,7 @@ module.exports = function (grunt) { // eslint-disable-line
|
||||||
"!archive/**",
|
"!archive/**",
|
||||||
"!deploy/**",
|
"!deploy/**",
|
||||||
"!mithril.closure-compiler-externs.js",
|
"!mithril.closure-compiler-externs.js",
|
||||||
"!docs/layout/lib/**",
|
"!docs/layout/lib/**"
|
||||||
// TODO(impinball): Finish this.
|
|
||||||
"!mithril.js"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -367,7 +365,7 @@ module.exports = function (grunt) { // eslint-disable-line
|
||||||
grunt.loadNpmTasks("grunt-mocha-phantomjs")
|
grunt.loadNpmTasks("grunt-mocha-phantomjs")
|
||||||
|
|
||||||
grunt.registerTask("build", [
|
grunt.registerTask("build", [
|
||||||
//"lint",
|
// "lint",
|
||||||
"test",
|
"test",
|
||||||
"uglify",
|
"uglify",
|
||||||
"zip",
|
"zip",
|
||||||
|
|
|
||||||
186
mithril.js
186
mithril.js
|
|
@ -235,8 +235,10 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
var actions = []
|
var actions = []
|
||||||
for (var prop in existing) if (hasOwn.call(existing, prop)) {
|
for (var prop in existing) {
|
||||||
actions.push(existing[prop])
|
if (hasOwn.call(existing, prop)) {
|
||||||
|
actions.push(existing[prop])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var changes = actions.sort(sortChanges)
|
var changes = actions.sort(sortChanges)
|
||||||
|
|
@ -367,8 +369,10 @@
|
||||||
|
|
||||||
if (cached.controllers) {
|
if (cached.controllers) {
|
||||||
forEach(cached.controllers, function (controller) {
|
forEach(cached.controllers, function (controller) {
|
||||||
if (controller.onunload) controller.onunload({preventDefault: noop});
|
if (controller.onunload) {
|
||||||
});
|
controller.onunload({preventDefault: noop})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -749,7 +753,9 @@
|
||||||
var unloaders = []
|
var unloaders = []
|
||||||
|
|
||||||
function updateLists(views, controllers, view, controller) {
|
function updateLists(views, controllers, view, controller) {
|
||||||
if (controller.onunload != null && unloaders.map(function(u) {return u.handler}).indexOf(controller.onunload) < 0) {
|
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
|
||||||
|
|
@ -761,11 +767,32 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var forcing = false
|
var forcing = false
|
||||||
function checkView(data, view, cached, cachedControllers, controllers, views) {
|
function checkView(
|
||||||
var controller = getController(cached.views, view, cachedControllers, data.controller)
|
data,
|
||||||
|
view,
|
||||||
|
cached,
|
||||||
|
cachedControllers,
|
||||||
|
controllers,
|
||||||
|
views
|
||||||
|
) {
|
||||||
|
var controller = getController(
|
||||||
|
cached.views,
|
||||||
|
view,
|
||||||
|
cachedControllers,
|
||||||
|
data.controller)
|
||||||
|
|
||||||
var key = data && data.attrs && data.attrs.key
|
var key = data && data.attrs && data.attrs.key
|
||||||
data = pendingRequests === 0 || forcing || cachedControllers && cachedControllers.indexOf(controller) > -1 ? data.view(controller) : {tag: "placeholder"}
|
|
||||||
if (data.subtree === "retain") return data;
|
if (pendingRequests === 0 ||
|
||||||
|
forcing ||
|
||||||
|
cachedControllers &&
|
||||||
|
cachedControllers.indexOf(controller) > -1) {
|
||||||
|
data = data.view(controller)
|
||||||
|
} else {
|
||||||
|
data = {tag: "placeholder"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.subtree === "retain") return data
|
||||||
data.attrs = data.attrs || {}
|
data.attrs = data.attrs || {}
|
||||||
data.attrs.key = key
|
data.attrs.key = key
|
||||||
updateLists(views, controllers, view, controller)
|
updateLists(views, controllers, view, controller)
|
||||||
|
|
@ -972,14 +999,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyStyleAttrs(node, dataAttr, cachedAttr) {
|
function copyStyleAttrs(node, dataAttr, cachedAttr) {
|
||||||
for (var rule in dataAttr) if (hasOwn.call(dataAttr, rule)) {
|
for (var rule in dataAttr) {
|
||||||
if (cachedAttr == null || cachedAttr[rule] !== dataAttr[rule]) {
|
if (hasOwn.call(dataAttr, rule)) {
|
||||||
node.style[rule] = dataAttr[rule]
|
if (cachedAttr == null || cachedAttr[rule] !== dataAttr[rule]) {
|
||||||
|
node.style[rule] = dataAttr[rule]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (rule in cachedAttr) if (hasOwn.call(cachedAttr, rule)) {
|
for (rule in cachedAttr) {
|
||||||
if (!hasOwn.call(dataAttr, rule)) node.style[rule] = ""
|
if (hasOwn.call(cachedAttr, rule)) {
|
||||||
|
if (!hasOwn.call(dataAttr, rule)) node.style[rule] = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1075,16 +1106,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAttributes(node, tag, dataAttrs, cachedAttrs, namespace) {
|
function setAttributes(node, tag, dataAttrs, cachedAttrs, namespace) {
|
||||||
for (var attrName in dataAttrs) if (hasOwn.call(dataAttrs, attrName)) {
|
for (var attrName in dataAttrs) {
|
||||||
if (trySetAttr(
|
if (hasOwn.call(dataAttrs, attrName)) {
|
||||||
node,
|
if (trySetAttr(
|
||||||
attrName,
|
node,
|
||||||
dataAttrs[attrName],
|
attrName,
|
||||||
cachedAttrs[attrName],
|
dataAttrs[attrName],
|
||||||
cachedAttrs,
|
cachedAttrs[attrName],
|
||||||
tag,
|
cachedAttrs,
|
||||||
namespace)) {
|
tag,
|
||||||
continue
|
namespace)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cachedAttrs
|
return cachedAttrs
|
||||||
|
|
@ -1403,7 +1436,7 @@
|
||||||
try {
|
try {
|
||||||
// lastRedrawId is a positive number if a second redraw is requested
|
// lastRedrawId is a positive number if a second redraw is requested
|
||||||
// before the next animation frame
|
// before the next animation frame
|
||||||
// lastRedrawID is null if it's the first redraw and not an event
|
// lastRedrawId is null if it's the first redraw and not an event
|
||||||
// handler
|
// handler
|
||||||
if (lastRedrawId && !force) {
|
if (lastRedrawId && !force) {
|
||||||
// when setTimeout: only reschedule redraw if time between now
|
// when setTimeout: only reschedule redraw if time between now
|
||||||
|
|
@ -1544,8 +1577,10 @@
|
||||||
params = {}
|
params = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i in args) if (hasOwn.call(args, i)) {
|
for (var i in args) {
|
||||||
params[i] = args[i]
|
if (hasOwn.call(args, i)) {
|
||||||
|
params[i] = args[i]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var querystring = buildQueryString(params)
|
var querystring = buildQueryString(params)
|
||||||
|
|
@ -1621,29 +1656,31 @@
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var route in router) if (hasOwn.call(router, route)) {
|
for (var route in router) {
|
||||||
if (route === path) {
|
if (hasOwn.call(router, route)) {
|
||||||
m.mount(root, router[route])
|
if (route === path) {
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var matcher = new RegExp("^" + route
|
|
||||||
.replace(/:[^\/]+?\.{3}/g, "(.*?)")
|
|
||||||
.replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
|
|
||||||
|
|
||||||
if (matcher.test(path)) {
|
|
||||||
/* eslint-disable no-loop-func */
|
|
||||||
path.replace(matcher, function () {
|
|
||||||
var keys = route.match(/:[^\/]+/g) || []
|
|
||||||
var values = [].slice.call(arguments, 1, -2)
|
|
||||||
forEach(keys, function (key, i) {
|
|
||||||
routeParams[key.replace(/:|\./g, "")] =
|
|
||||||
decodeURIComponent(values[i])
|
|
||||||
})
|
|
||||||
m.mount(root, router[route])
|
m.mount(root, router[route])
|
||||||
})
|
return true
|
||||||
/* eslint-enable no-loop-func */
|
}
|
||||||
return true
|
|
||||||
|
var matcher = new RegExp("^" + route
|
||||||
|
.replace(/:[^\/]+?\.{3}/g, "(.*?)")
|
||||||
|
.replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
|
||||||
|
|
||||||
|
if (matcher.test(path)) {
|
||||||
|
/* eslint-disable no-loop-func */
|
||||||
|
path.replace(matcher, function () {
|
||||||
|
var keys = route.match(/:[^\/]+/g) || []
|
||||||
|
var values = [].slice.call(arguments, 1, -2)
|
||||||
|
forEach(keys, function (key, i) {
|
||||||
|
routeParams[key.replace(/:|\./g, "")] =
|
||||||
|
decodeURIComponent(values[i])
|
||||||
|
})
|
||||||
|
m.mount(root, router[route])
|
||||||
|
})
|
||||||
|
/* eslint-enable no-loop-func */
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1689,32 +1726,35 @@
|
||||||
var duplicates = {}
|
var duplicates = {}
|
||||||
var str = []
|
var str = []
|
||||||
|
|
||||||
for (var prop in object) if (hasOwn.call(object, prop)) {
|
for (var prop in object) {
|
||||||
var key = prefix ? prefix + "[" + prop + "]" : prop
|
if (hasOwn.call(object, prop)) {
|
||||||
var value = object[prop]
|
var key = prefix ? prefix + "[" + prop + "]" : prop
|
||||||
|
var value = object[prop]
|
||||||
|
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
str.push(encodeURIComponent(key))
|
str.push(encodeURIComponent(key))
|
||||||
} else if (isObject(value)) {
|
} else if (isObject(value)) {
|
||||||
str.push(buildQueryString(value, key))
|
str.push(buildQueryString(value, key))
|
||||||
} else if (isArray(value)) {
|
} else if (isArray(value)) {
|
||||||
var keys = []
|
var keys = []
|
||||||
duplicates[key] = duplicates[key] || {}
|
duplicates[key] = duplicates[key] || {}
|
||||||
/* eslint-disable no-loop-func */
|
/* eslint-disable no-loop-func */
|
||||||
forEach(value, function (item) {
|
forEach(value, function (item) {
|
||||||
/* eslint-enable no-loop-func */
|
/* eslint-enable no-loop-func */
|
||||||
if (!duplicates[key][item]) {
|
if (!duplicates[key][item]) {
|
||||||
duplicates[key][item] = true
|
duplicates[key][item] = true
|
||||||
keys.push(encodeURIComponent(key) + "=" +
|
keys.push(encodeURIComponent(key) + "=" +
|
||||||
encodeURIComponent(item))
|
encodeURIComponent(item))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
str.push(keys.join("&"))
|
str.push(keys.join("&"))
|
||||||
} else if (value !== undefined) {
|
} else if (value !== undefined) {
|
||||||
str.push(encodeURIComponent(key) + "=" +
|
str.push(encodeURIComponent(key) + "=" +
|
||||||
encodeURIComponent(value))
|
encodeURIComponent(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.join("&")
|
return str.join("&")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2060,7 +2100,7 @@
|
||||||
|
|
||||||
function parameterizeUrl(url, data) {
|
function parameterizeUrl(url, data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
url = url.replace(/:[a-z]\w+/gi, function(token){
|
url = url.replace(/:[a-z]\w+/gi, function (token){
|
||||||
var key = token.slice(1)
|
var key = token.slice(1)
|
||||||
var value = data[key]
|
var value = data[key]
|
||||||
delete data[key]
|
delete data[key]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue