Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
solkimicreb committed Oct 3, 2018
1 parent e6d365b commit 700dfbd
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/scheduler.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
const tasks = new Set()
let isStopped = false

export function add(task) {
export function add (task) {
if (isStopped) {
tasks.add(task)
} else {
runTask(task)
}
}

export function remove(task) {
export function remove (task) {
tasks.delete(task)
}

// this replaces the passed function with a function
// that batches all of its callback arguments
function batch(fn) {
return function batchingCallbacks(...args) {
function batch (fn) {
return function batchingCallbacks (...args) {
const batchedArgs = args.map(
arg =>
typeof arg === 'function'
? function batchedCallback() {
try {
isStopped = true
return arg.apply(this, arguments)
} finally {
tasks.forEach(runTask)
tasks.clear()
isStopped = false
}
? function batchedCallback () {
try {
isStopped = true
return arg.apply(this, arguments)
} finally {
tasks.forEach(runTask)
tasks.clear()
isStopped = false
}
}
: arg
)
return fn.apply(this, batchedArgs)
}
}

function runTask(task) {
function runTask (task) {
task()
}

Expand All @@ -55,9 +55,9 @@ if (globalObj) {
globalObj.setTimeout = batch(globalObj.setTimeout)
globalObj.setInterval = batch(globalObj.setInterval)
// eslint-disable-next-line
Promise.prototype.then = batch(Promise.prototype.then)
Promise.prototype.then = batch(Promise.prototype.then);
// eslint-disable-next-line
Promise.prototype.catch = batch(Promise.prototype.catch)
Promise.prototype.catch = batch(Promise.prototype.catch);
}

// DOM event handlers and HTTP event handlers don't have to be batched
Expand Down

0 comments on commit 700dfbd

Please sign in to comment.