{"comment":{"url":"https://api.github.com/repos/jasonody/react-rjsdaq-workshop/comments/12669125","html_url":"https://github.com/jasonody/react-rjsdaq-workshop/commit/ef9d1454a3a7a474797d5d9a7c9ea5b1c14ef552#commitcomment-12669125","id":12669125,"user":{"login":"steveluscher","id":13243,"avatar_url":"https://avatars.githubusercontent.com/u/13243?v=3","gravatar_id":"","url":"https://api.github.com/users/steveluscher","html_url":"https://github.com/steveluscher","followers_url":"https://api.github.com/users/steveluscher/followers","following_url":"https://api.github.com/users/steveluscher/following{/other_user}","gists_url":"https://api.github.com/users/steveluscher/gists{/gist_id}","starred_url":"https://api.github.com/users/steveluscher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveluscher/subscriptions","organizations_url":"https://api.github.com/users/steveluscher/orgs","repos_url":"https://api.github.com/users/steveluscher/repos","events_url":"https://api.github.com/users/steveluscher/events{/privacy}","received_events_url":"https://api.github.com/users/steveluscher/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"ef9d1454a3a7a474797d5d9a7c9ea5b1c14ef552","created_at":"2015-08-12T16:39:50Z","updated_at":"2015-08-12T16:39:50Z","body":"I imagine that the timer would live in a separate module; something like\r\n\r\n```\r\nimport BatchingTimer from '…';\r\nBatchingTimer.batchExecutor = React.unstable_batchedUpdates;\r\nBatchingTimer.setInterval(this.updatePriceAge, 1000);\r\n```\r\n\r\nAnd then in BatchingTimer:\r\n\r\n```\r\nvar tasks = [];\r\nfunction maybeStartTimer() {\r\n  // Look at the `maybeInit` function of Chronos\r\n  // https://github.com/fitzgen/chronos/blob/master/chronos.js\r\n  // I'd rather see an implementation where the single timer had\r\n  // a variable `INTERVAL` rather than a fixed one, where the\r\n  // cycle was based on requestAnimationFrame and not setTimeout\r\n  // and where the bookkeeping was based on absolute time\r\n  // rather than time to `next` invocation (maybe with an option that\r\n  // delivered guaranteed execution, or allowed the timer to drop \r\n  // tasks if they've missed their window of opportunity.\r\n}\r\nfunction executeBatch() {\r\n  // Find all of the `fn` that are overdue\r\n  var overdueTasks = tasks.filter(/* ... */);\r\n  if (BatchingTimer.batchExecutor) {\r\n    BatchingTimer.batchExecutor(() => \r\n      overdueTasks.forEach(fn => fn())\r\n    );\r\n  } else {\r\n    overdueTasks.forEach(fn => fn())\r\n  }\r\n}\r\nexport class BatchingTimer {\r\n  static batchExecutor;\r\n  static setInterval(fn, ms) {\r\n    // Add `fn` to a list of tracked tasks that should be fired whenever `ms` milliseconds elapses\r\n    maybeStartTimer();\r\n    return intervalId;\r\n  }\r\n}\r\n```\r\n\r\n…but anyway. We digress from React :)"}}