Merge pull request #973 from isiahmeadows/lint

Make linter happy with mithril.js
This commit is contained in:
Isiah Meadows 2016-03-17 23:56:13 -04:00
commit 806e0a8dc1
2 changed files with 114 additions and 76 deletions

View file

@ -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"
] ]
}, },

View file

@ -239,9 +239,11 @@
}) })
var actions = [] var actions = []
for (var prop in existing) if (hasOwn.call(existing, prop)) { for (var prop in existing) {
if (hasOwn.call(existing, prop)) {
actions.push(existing[prop]) actions.push(existing[prop])
} }
}
var changes = actions.sort(sortChanges) var changes = actions.sort(sortChanges)
var newCached = new Array(cached.length) var newCached = new Array(cached.length)
@ -371,8 +373,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})
}
})
} }
} }
} }
@ -753,7 +757,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
@ -765,11 +771,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)
@ -976,16 +1003,20 @@
} }
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 (hasOwn.call(dataAttr, rule)) {
if (cachedAttr == null || cachedAttr[rule] !== dataAttr[rule]) { if (cachedAttr == null || cachedAttr[rule] !== dataAttr[rule]) {
node.style[rule] = dataAttr[rule] node.style[rule] = dataAttr[rule]
} }
} }
}
for (rule in cachedAttr) if (hasOwn.call(cachedAttr, rule)) { for (rule in cachedAttr) {
if (hasOwn.call(cachedAttr, rule)) {
if (!hasOwn.call(dataAttr, rule)) node.style[rule] = "" if (!hasOwn.call(dataAttr, rule)) node.style[rule] = ""
} }
} }
}
var shouldUseSetAttribute = { var shouldUseSetAttribute = {
list: 1, list: 1,
@ -1079,7 +1110,8 @@
} }
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 (hasOwn.call(dataAttrs, attrName)) {
if (trySetAttr( if (trySetAttr(
node, node,
attrName, attrName,
@ -1091,6 +1123,7 @@
continue continue
} }
} }
}
return cachedAttrs return cachedAttrs
} }
@ -1407,7 +1440,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
@ -1548,9 +1581,11 @@
params = {} params = {}
} }
for (var i in args) if (hasOwn.call(args, i)) { for (var i in args) {
if (hasOwn.call(args, i)) {
params[i] = args[i] params[i] = args[i]
} }
}
var querystring = buildQueryString(params) var querystring = buildQueryString(params)
var currentPath var currentPath
@ -1625,7 +1660,8 @@
return true return true
} }
for (var route in router) if (hasOwn.call(router, route)) { for (var route in router) {
if (hasOwn.call(router, route)) {
if (route === path) { if (route === path) {
m.mount(root, router[route]) m.mount(root, router[route])
return true return true
@ -1651,6 +1687,7 @@
} }
} }
} }
}
function routeUnobtrusive(e) { function routeUnobtrusive(e) {
e = e || event e = e || event
@ -1693,7 +1730,8 @@
var duplicates = {} var duplicates = {}
var str = [] var str = []
for (var prop in object) if (hasOwn.call(object, prop)) { for (var prop in object) {
if (hasOwn.call(object, prop)) {
var key = prefix ? prefix + "[" + prop + "]" : prop var key = prefix ? prefix + "[" + prop + "]" : prop
var value = object[prop] var value = object[prop]
@ -1719,6 +1757,8 @@
encodeURIComponent(value)) encodeURIComponent(value))
} }
} }
}
return str.join("&") return str.join("&")
} }