Stateful.js 646 B

123456789101112131415161718192021222324252627282930
  1. var States = require("../States");
  2. /**
  3. * Stateful mixin for graphic object
  4. */
  5. var Stateful = function (opts) {
  6. if (opts.states) {
  7. this.initStates(opts.states);
  8. }
  9. };
  10. Stateful.prototype = {
  11. initStates: function (states) {
  12. this._states = new States({
  13. el: this,
  14. states: states
  15. });
  16. },
  17. setState: function (name) {
  18. this._states && this._states.setState(name);
  19. },
  20. getState: function () {
  21. return this._states && this._states.getState();
  22. },
  23. transitionState: function (name, done) {
  24. this._states && this._states.transitionState(name, done);
  25. }
  26. };
  27. var _default = Stateful;
  28. module.exports = _default;