Lint
This commit is contained in:
parent
47d59ea68a
commit
0e0ed7c45d
5 changed files with 88 additions and 86 deletions
|
|
@ -11,7 +11,6 @@ var apiRedraw = require("../../api/redraw")
|
|||
var apiMounter = require("../../api/mount")
|
||||
|
||||
o.spec("mount", function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redrawService, mount, render, throttleMock
|
||||
|
||||
o.beforeEach(function() {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ o.spec("route", function() {
|
|||
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
|
||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
||||
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
|
||||
var FRAME_BUDGET = Math.floor(1000 / 60)
|
||||
var $window, root, redrawService, route, throttleMock
|
||||
|
||||
o.beforeEach(function() {
|
||||
|
|
@ -552,12 +551,12 @@ o.spec("route", function() {
|
|||
route(root, "/a", {
|
||||
"/a" : {
|
||||
render: function() {
|
||||
return m("div", m('p'))
|
||||
return m("div", m("p"))
|
||||
},
|
||||
},
|
||||
"/b" : {
|
||||
render: function() {
|
||||
return m("div", m('a'))
|
||||
return m("div", m("a"))
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
@ -840,7 +839,7 @@ o.spec("route", function() {
|
|||
callAsync(function() {
|
||||
throttleMock.fire()
|
||||
|
||||
route.set('/b')
|
||||
route.set("/b")
|
||||
callAsync(function() {
|
||||
callAsync(function() {
|
||||
callAsync(function() {
|
||||
|
|
@ -1110,7 +1109,7 @@ o.spec("route", function() {
|
|||
|
||||
o(root.firstChild.nodeName).equals("B")
|
||||
|
||||
route.set('/a')
|
||||
route.set("/a")
|
||||
|
||||
callAsync(function() {
|
||||
throttleMock.fire()
|
||||
|
|
|
|||
|
|
@ -1,89 +1,91 @@
|
|||
"use strict"
|
||||
|
||||
var o = require("../../ospec/ospec")
|
||||
var throttleMocker = require("../../test-utils/throttleMock")
|
||||
|
||||
o.spec("throttleMock", function() {
|
||||
o("works with one callback", function() {
|
||||
var throttleMock = throttleMocker()
|
||||
var spy = o.spy()
|
||||
o("works with one callback", function() {
|
||||
var throttleMock = throttleMocker()
|
||||
var spy = o.spy()
|
||||
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
|
||||
var throttled = throttleMock.throttle(spy)
|
||||
var throttled = throttleMock.throttle(spy)
|
||||
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy.callCount).equals(0)
|
||||
|
||||
throttled()
|
||||
throttled()
|
||||
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy.callCount).equals(0)
|
||||
|
||||
throttled()
|
||||
throttled()
|
||||
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy.callCount).equals(0)
|
||||
|
||||
throttleMock.fire()
|
||||
throttleMock.fire()
|
||||
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy.callCount).equals(1)
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy.callCount).equals(1)
|
||||
|
||||
throttleMock.fire()
|
||||
throttleMock.fire()
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
o("works with two callbacks", function() {
|
||||
var throttleMock = throttleMocker()
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
o(spy.callCount).equals(1)
|
||||
})
|
||||
o("works with two callbacks", function() {
|
||||
var throttleMock = throttleMocker()
|
||||
var spy1 = o.spy()
|
||||
var spy2 = o.spy()
|
||||
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
|
||||
var throttled1 = throttleMock.throttle(spy1)
|
||||
var throttled1 = throttleMock.throttle(spy1)
|
||||
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
|
||||
throttled1()
|
||||
throttled1()
|
||||
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
|
||||
throttled1()
|
||||
throttled1()
|
||||
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
|
||||
var throttled2 = throttleMock.throttle(spy2)
|
||||
var throttled2 = throttleMock.throttle(spy2)
|
||||
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(1)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
|
||||
throttled2()
|
||||
throttled2()
|
||||
|
||||
o(throttleMock.queueLength()).equals(2)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(2)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
|
||||
throttled2()
|
||||
throttled2()
|
||||
|
||||
o(throttleMock.queueLength()).equals(2)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
o(throttleMock.queueLength()).equals(2)
|
||||
o(spy1.callCount).equals(0)
|
||||
o(spy2.callCount).equals(0)
|
||||
|
||||
throttleMock.fire()
|
||||
throttleMock.fire()
|
||||
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
o(throttleMock.queueLength()).equals(0)
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
|
||||
throttleMock.fire()
|
||||
throttleMock.fire()
|
||||
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
})
|
||||
o(spy1.callCount).equals(1)
|
||||
o(spy2.callCount).equals(1)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
"use strict"
|
||||
|
||||
module.exports = function() {
|
||||
var queue = []
|
||||
return {
|
||||
throttle: function(fn) {
|
||||
var pending = false
|
||||
return function() {
|
||||
if (!pending) {
|
||||
queue.push(function(){
|
||||
pending = false
|
||||
fn()
|
||||
})
|
||||
pending = true
|
||||
}
|
||||
}
|
||||
},
|
||||
fire: function() {
|
||||
var tasks = queue
|
||||
queue = []
|
||||
tasks.forEach(function(fn) {fn()})
|
||||
},
|
||||
queueLength: function(){
|
||||
return queue.length
|
||||
}
|
||||
}
|
||||
var queue = []
|
||||
return {
|
||||
throttle: function(fn) {
|
||||
var pending = false
|
||||
return function() {
|
||||
if (!pending) {
|
||||
queue.push(function(){
|
||||
pending = false
|
||||
fn()
|
||||
})
|
||||
pending = true
|
||||
}
|
||||
}
|
||||
},
|
||||
fire: function() {
|
||||
var tasks = queue
|
||||
queue = []
|
||||
tasks.forEach(function(fn) {fn()})
|
||||
},
|
||||
queueLength: function(){
|
||||
return queue.length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue