租房小程序前端代码
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.

73 lines
2.4 KiB

3 months ago
  1. get-ready
  2. =====
  3. [![NPM version][npm-image]][npm-url]
  4. [![build status][travis-image]][travis-url]
  5. [![Test coverage][codecov-image]][codecov-url]
  6. [![David deps][david-image]][david-url]
  7. [![npm download][download-image]][download-url]
  8. [npm-image]: https://img.shields.io/npm/v/get-ready.svg?style=flat-square
  9. [npm-url]: https://npmjs.org/package/get-ready
  10. [travis-image]: https://img.shields.io/travis/node-modules/ready.svg?style=flat-square
  11. [travis-url]: https://travis-ci.org/node-modules/ready
  12. [codecov-image]: https://codecov.io/github/node-modules/ready/coverage.svg?branch=master
  13. [codecov-url]: https://codecov.io/github/node-modules/ready?branch=master
  14. [david-image]: https://img.shields.io/david/node-modules/ready.svg?style=flat-square
  15. [david-url]: https://david-dm.org/node-modules/ready
  16. [download-image]: https://img.shields.io/npm/dm/get-ready.svg?style=flat-square
  17. [download-url]: https://npmjs.org/package/get-ready
  18. **Fork from [supershabam/ready](https://github.com/supershabam/ready)**
  19. NodeJS mixin to add one-time ready event
  20. ## Purpose
  21. Events are great. You should use events, but not for signaling ready! Ready implies state, and once you are ready, you stay ready.
  22. This is a module for everyone who has bound an event handler.on('ready', function() {}) that doesn't execute because you added the handler after the 'ready' event already fired.
  23. ## Warning
  24. If you use this mixin, you must have 'ready', '_ready', and '_readyCallbacks' available on your class. Ready will stomp on these variables if you're trying to use them in your class.
  25. ## Example
  26. ```javascript
  27. var ready = require('ready');
  28. // example class that uses Ready
  29. function MyClass() {
  30. this.someProperty = 'some value';
  31. }
  32. ready.mixin(MyClass.prototype);
  33. // Normal class prototype functions
  34. MyClass.prototype.doSomeWork = function() {};
  35. // Create a new class that uses ready mixin
  36. var myClass = new MyClass();
  37. // Add callback for when myClass is ready
  38. myClass.ready(function() {
  39. console.log('I am now ready');
  40. });
  41. myClass.doSomeWork();
  42. // We are now ready, fire callbacks!
  43. myClass.ready(true);
  44. // Adding a new callback once we're already ready gets executed immediately
  45. myClass.ready(function() {
  46. console.log('I came late to the party, but I will still execute.');
  47. });
  48. // Ok, you can set the ready state to false now as well... for whatever reason
  49. myClass.ready(false);
  50. myClass.ready(function() {
  51. console.log('I will not fire until you set ready to true again.');
  52. });
  53. ```
  54. ## License
  55. [MIT](LICENSE)