bind-event.js 610 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.BindEventMixin = BindEventMixin;
  4. var _event = require("../utils/dom/event");
  5. /**
  6. * Bind event when mounted or activated
  7. */
  8. var uid = 0;
  9. function BindEventMixin(handler) {
  10. var key = "binded_" + uid++;
  11. function bind() {
  12. if (!this[key]) {
  13. handler.call(this, _event.on, true);
  14. this[key] = true;
  15. }
  16. }
  17. function unbind() {
  18. if (this[key]) {
  19. handler.call(this, _event.off, false);
  20. this[key] = false;
  21. }
  22. }
  23. return {
  24. mounted: bind,
  25. activated: bind,
  26. deactivated: unbind,
  27. beforeDestroy: unbind
  28. };
  29. }