let scheduler = null

export function setScheduler (customScheduler) {
  if (customScheduler) {
    scheduler = customScheduler
  } else {
    scheduler = new DefaultScheduler()
  }
}

export function getScheduler () {
  return scheduler
}

class DefaultScheduler {
  constructor () {
    this.updateRequests = []
    this.frameRequested = false
    this.performUpdates = this.performUpdates.bind(this)
  }

  updateDocument (fn) {
    this.updateRequests.push(fn)
    if (!this.frameRequested) {
      this.frameRequested = true
      window.requestAnimationFrame(this.performUpdates)
    }
  }

  performUpdates () {
    this.frameRequested = false

    while (this.updateRequests.length > 0) {
      this.updateRequests.shift()()
    }
  }
}

@@ -70,71 +70,90 @@
 %7B%0A  
-if (customScheduler) %7B%0A    scheduler = customScheduler%0A  %7D else
+scheduler = customScheduler%0A%7D%0A%0Aexport function getScheduler () %7B%0A  if (!scheduler)
  %7B%0A 
@@ -198,45 +198,8 @@
   %7D%0A
-%7D%0A%0Aexport function getScheduler () %7B%0A
   re

Use the DefaultScheduler if none is assigned