IdClaimHandler.js 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @typedef {import('diagram-js/lib/command/CommandHandler').default} CommandHandler
  3. *
  4. * @typedef {import('../../../model/Types').Moddle} Moddle
  5. */
  6. /**
  7. * @implements {CommandHandler}
  8. *
  9. * @param {Moddle} moddle
  10. */
  11. export default function IdClaimHandler(moddle) {
  12. this._moddle = moddle;
  13. }
  14. IdClaimHandler.$inject = [ 'moddle' ];
  15. IdClaimHandler.prototype.execute = function(context) {
  16. var ids = this._moddle.ids,
  17. id = context.id,
  18. element = context.element,
  19. claiming = context.claiming;
  20. if (claiming) {
  21. ids.claim(id, element);
  22. } else {
  23. ids.unclaim(id);
  24. }
  25. return [];
  26. };
  27. /**
  28. * Command revert implementation.
  29. */
  30. IdClaimHandler.prototype.revert = function(context) {
  31. var ids = this._moddle.ids,
  32. id = context.id,
  33. element = context.element,
  34. claiming = context.claiming;
  35. if (claiming) {
  36. ids.unclaim(id);
  37. } else {
  38. ids.claim(id, element);
  39. }
  40. return [];
  41. };