diff --git a/packages/omi-mobx/index.js b/packages/omi-mobx/index.js index eb4cf04f3..54404a0c1 100644 --- a/packages/omi-mobx/index.js +++ b/packages/omi-mobx/index.js @@ -20,58 +20,58 @@ import { options } from "omi"; /* * @see https://developers.google.com/web/updates/2015/08/using-requestidlecallback */ -window.requestIdleCallback = window.requestIdleCallback || - function (cb) { - return setTimeout(function () { - var start = Date.now() - cb({ - didTimeout: false, - timeRemaining: function () { - return Math.max(0, 50 - (Date.now() - start)) - } - }) - }, 1) - } +window.requestIdleCallback = + window.requestIdleCallback || + function(cb) { + return setTimeout(function() { + var start = Date.now(); + cb({ + didTimeout: false, + timeRemaining: function() { + return Math.max(0, 50 - (Date.now() - start)); + } + }); + }, 1); + }; -window.cancelIdleCallback = window.cancelIdleCallback || - function (id) { - clearTimeout(id) - } +window.cancelIdleCallback = + window.cancelIdleCallback || + function(id) { + clearTimeout(id); + }; +options.afterInstall = function(ele) { + if (ele.constructor.observe) { + oba(ele.data, ele); + } +}; -options.afterInstall = function (ele) { - if (ele.constructor.observe) { - oba(ele.data, ele) - } -} - -let idleId = null -const updateList = [] +let idleId = null; +const updateList = []; function oba(data, ele) { - const o = observable(data) + const o = observable(data); - autorun(() => { - JSON.stringify(o) - if (ele._isInstalled) { - updateList.push(ele) - cancelIdleCallback(idleId) - idleId = requestIdleCallback(backgroundTask) + autorun(() => { + JSON.stringify(o); + if (ele._isInstalled) { + updateList.push(ele); + cancelIdleCallback(idleId); + idleId = requestIdleCallback(backgroundTask); + } + }); - } - }) - - ele.data = o + ele.data = o; } function backgroundTask(deadline) { - while (deadline.timeRemaining() > 0 && updateList.length > 0) { - updateList.shift().update() - } + while (deadline.timeRemaining() > 0 && updateList.length > 0) { + updateList.shift().update(); + } - if (updateList.length > 0) { - idleId = requestIdleCallback(backgroundTask); - } + if (updateList.length > 0) { + idleId = requestIdleCallback(backgroundTask); + } } function observe(target) { diff --git a/packages/omi/examples/mobx/omi-mobx.js b/packages/omi/examples/mobx/omi-mobx.js index f1fe566cb..efbbd087a 100644 --- a/packages/omi/examples/mobx/omi-mobx.js +++ b/packages/omi/examples/mobx/omi-mobx.js @@ -1,5 +1,5 @@ -import { observable, autorun } from "mobx"; -import { options } from "../../src/omi"; +import { observable, autorun } from "mobx" +import { options } from "../../src/omi" /*! * Copyright 2015 Google Inc. All rights reserved. @@ -20,66 +20,66 @@ import { options } from "../../src/omi"; /* * @see https://developers.google.com/web/updates/2015/08/using-requestidlecallback */ -window.requestIdleCallback = window.requestIdleCallback || - function (cb) { - return setTimeout(function () { - var start = Date.now() - cb({ - didTimeout: false, - timeRemaining: function () { - return Math.max(0, 50 - (Date.now() - start)) - } - }) - }, 1) - } +window.requestIdleCallback = + window.requestIdleCallback || + function(cb) { + return setTimeout(() => { + let start = Date.now() + cb({ + didTimeout: false, + timeRemaining() { + return Math.max(0, 50 - (Date.now() - start)) + } + }) + }, 1) + } -window.cancelIdleCallback = window.cancelIdleCallback || - function (id) { - clearTimeout(id) - } +window.cancelIdleCallback = + window.cancelIdleCallback || + function(id) { + clearTimeout(id) + } - -options.afterInstall = function (ele) { - if (ele.constructor.observe) { - oba(ele.data, ele) - } +options.afterInstall = function(ele) { + if (ele.constructor.observe) { + oba(ele.data, ele) + } } let idleId = null const updateList = [] function oba(data, ele) { - const o = observable(data) + const o = observable(data) - autorun(() => { - JSON.stringify(o) - if (ele._isInstalled) { - updateList.push(ele) - cancelIdleCallback(idleId) - idleId = requestIdleCallback(backgroundTask) + autorun(() => { + JSON.stringify(o) + if (ele._isInstalled) { + updateList.push(ele) + cancelIdleCallback(idleId) + idleId = requestIdleCallback(backgroundTask) + } + }) - } - }) - - ele.data = o + ele.data = o } function backgroundTask(deadline) { - while (deadline.timeRemaining() > 0 && updateList.length > 0) { - updateList.shift().update() - } + while (deadline.timeRemaining() > 0 && updateList.length > 0) { + updateList.shift().update() + } - if (updateList.length > 0) { - idleId = requestIdleCallback(backgroundTask); - } + if (updateList.length > 0) { + idleId = requestIdleCallback(backgroundTask) + } } function observe(target) { - target.observe = true; + target.observe = true } -export { observe }; +export { observe } export default { observe -}; +}