"use strict" var Vnode = require("../render/vnode") module.exports = function(redrawService) { function throttle(callback) { //60fps translates to 16.6ms, round it down since setTimeout requires int var time = 16 var last = 0, pending = null var timeout = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout return function() { var now = Date.now() if (last === 0 || now - last >= time) { last = now callback() } else if (pending === null) { pending = timeout(function() { pending = null callback() last = Date.now() }, time - (now - last)) } } } return function(root, component) { if (component === null) { redrawService.render(root, []) redrawService.unsubscribe(root) return } if (component.view == null) throw new Error("m.mount(element, component) expects a component, not a vnode") var run = throttle(function() { redrawService.render(root, Vnode(component)) }) redrawService.subscribe(root, run) run() } }