modelUtil.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { some } from 'min-dash';
  2. /**
  3. * Is an element of the given BPMN type?
  4. *
  5. * @param {djs.model.Base|ModdleElement} element
  6. * @param {string} type
  7. *
  8. * @return {boolean}
  9. */
  10. export function is(element: any, type: any) {
  11. var bo = getBusinessObject(element);
  12. return bo && typeof bo.$instanceOf === 'function' && bo.$instanceOf(type);
  13. }
  14. /**
  15. * Return true if element has any of the given types.
  16. *
  17. * @param {djs.model.Base} element
  18. * @param {Array<string>} types
  19. *
  20. * @return {boolean}
  21. */
  22. export function isAny(element: any, types: any) {
  23. return some(types, function (t: any) {
  24. return is(element, t);
  25. });
  26. }
  27. /**
  28. * Return the business object for a given element.
  29. *
  30. * @param {djs.model.Base|ModdleElement} element
  31. *
  32. * @return {ModdleElement}
  33. */
  34. export function getBusinessObject(element: any) {
  35. return (element && element.businessObject) || element;
  36. }
  37. /**
  38. * Return the di object for a given element.
  39. *
  40. * @param {djs.model.Base} element
  41. *
  42. * @return {ModdleElement}
  43. */
  44. export function getDi(element: any) {
  45. return element && element.di;
  46. }