用工小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
826 B

6 months ago
  1. 'use strict';
  2. function ready(flagOrFunction) {
  3. this._ready = !!this._ready;
  4. this._readyCallbacks = this._readyCallbacks || [];
  5. if (arguments.length === 0) {
  6. // return a promise
  7. // support `this.ready().then(onready);` and `yield this.ready()`;
  8. return new Promise(function (resolve) {
  9. if (this._ready) {
  10. return resolve();
  11. }
  12. this._readyCallbacks.push(resolve);
  13. }.bind(this));
  14. } else if (typeof flagOrFunction === 'function') {
  15. this._readyCallbacks.push(flagOrFunction);
  16. } else {
  17. this._ready = !!flagOrFunction;
  18. }
  19. if (this._ready) {
  20. this._readyCallbacks.splice(0, Infinity).forEach(function(callback) {
  21. process.nextTick(callback);
  22. });
  23. }
  24. }
  25. function mixin(object) {
  26. object.ready = ready;
  27. }
  28. module.exports = mixin;
  29. module.exports.mixin = mixin;