mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-02-19 20:28:06 +00:00
feat(util/ModelUtil): expose isAny
It is a core utility that will be tree-shaken if not used. We'll continue to expose it via `ModelingUtil` for backwards compatibility.
This commit is contained in:
parent
99516bc19b
commit
a42ba5cd90
@ -1,24 +1,6 @@
|
|||||||
import {
|
export { is, isAny } from '../../../util/ModelUtil';
|
||||||
some
|
|
||||||
} from 'min-dash';
|
|
||||||
|
|
||||||
import { is } from '../../../util/ModelUtil';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if element has any of the given types.
|
|
||||||
*
|
|
||||||
* @param {djs.model.Base} element
|
|
||||||
* @param {Array<string>} types
|
|
||||||
*
|
|
||||||
* @return {boolean}
|
|
||||||
*/
|
|
||||||
export function isAny(element, types) {
|
|
||||||
return some(types, function(t) {
|
|
||||||
return is(element, t);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
import { isAny } from '../../../util/ModelUtil';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the parent of the element with any of the given types.
|
* Return the parent of the element with any of the given types.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
import {
|
||||||
|
some
|
||||||
|
} from 'min-dash';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is an element of the given BPMN type?
|
* Is an element of the given BPMN type?
|
||||||
*
|
*
|
||||||
@ -13,6 +18,20 @@ export function is(element, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if element has any of the given types.
|
||||||
|
*
|
||||||
|
* @param {djs.model.Base} element
|
||||||
|
* @param {Array<string>} types
|
||||||
|
*
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
export function isAny(element, types) {
|
||||||
|
return some(types, function(t) {
|
||||||
|
return is(element, t);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the business object for a given element.
|
* Return the business object for a given element.
|
||||||
*
|
*
|
||||||
|
@ -8,6 +8,7 @@ import modelingModule from 'lib/features/modeling';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
is,
|
is,
|
||||||
|
isAny,
|
||||||
getDi
|
getDi
|
||||||
} from 'lib/util/ModelUtil';
|
} from 'lib/util/ModelUtil';
|
||||||
|
|
||||||
@ -24,51 +25,85 @@ describe('util/ModelUtil', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should work with diagram element', inject(function(elementFactory) {
|
describe('#is', function() {
|
||||||
|
|
||||||
// given
|
it('should work with diagram element', inject(function(elementFactory) {
|
||||||
var messageFlowConnection = elementFactory.createConnection({ type: 'bpmn:MessageFlow' });
|
|
||||||
|
|
||||||
// then
|
// given
|
||||||
expect(is(messageFlowConnection, 'bpmn:MessageFlow')).to.be.true;
|
var messageFlowConnection = elementFactory.createConnection({ type: 'bpmn:MessageFlow' });
|
||||||
expect(is(messageFlowConnection, 'bpmn:BaseElement')).to.be.true;
|
|
||||||
|
|
||||||
expect(is(messageFlowConnection, 'bpmn:SequenceFlow')).to.be.false;
|
// then
|
||||||
expect(is(messageFlowConnection, 'bpmn:Task')).to.be.false;
|
expect(is(messageFlowConnection, 'bpmn:MessageFlow')).to.be.true;
|
||||||
}));
|
expect(is(messageFlowConnection, 'bpmn:BaseElement')).to.be.true;
|
||||||
|
|
||||||
|
expect(is(messageFlowConnection, 'bpmn:SequenceFlow')).to.be.false;
|
||||||
|
expect(is(messageFlowConnection, 'bpmn:Task')).to.be.false;
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should work with business object', inject(function(bpmnFactory) {
|
it('should work with business object', inject(function(bpmnFactory) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var gateway = bpmnFactory.create('bpmn:Gateway');
|
var gateway = bpmnFactory.create('bpmn:Gateway');
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(is(gateway, 'bpmn:Gateway')).to.be.true;
|
expect(is(gateway, 'bpmn:Gateway')).to.be.true;
|
||||||
expect(is(gateway, 'bpmn:BaseElement')).to.be.true;
|
expect(is(gateway, 'bpmn:BaseElement')).to.be.true;
|
||||||
|
|
||||||
expect(is(gateway, 'bpmn:SequenceFlow')).to.be.false;
|
expect(is(gateway, 'bpmn:SequenceFlow')).to.be.false;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should work with untyped business object', inject(function() {
|
it('should work with untyped business object', inject(function() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var foo = { businessObject: 'BAR' };
|
var foo = { businessObject: 'BAR' };
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(is(foo, 'FOO')).to.be.false;
|
expect(is(foo, 'FOO')).to.be.false;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should work with untyped diagram element', inject(function() {
|
it('should work with untyped diagram element', inject(function() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var foo = { };
|
var foo = { };
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(is(foo, 'FOO')).to.be.false;
|
expect(is(foo, 'FOO')).to.be.false;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('isAny', function() {
|
||||||
|
|
||||||
|
it('should work on shape', inject(function(bpmnFactory, elementFactory) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var element = elementFactory.createShape({ type: 'bpmn:Gateway' });
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(isAny(element, [ 'bpmn:Gateway' ])).to.be.true;
|
||||||
|
expect(isAny(element, [ 'bpmn:SequenceFlow', 'bpmn:Gateway' ])).to.be.true;
|
||||||
|
expect(isAny(element, [ 'bpmn:BaseElement' ])).to.be.true;
|
||||||
|
expect(isAny(element, [ 'bpmn:SequenceFlow' ])).to.be.false;
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should work on businessObject', inject(function(bpmnFactory, elementFactory) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var businessObject = bpmnFactory.create('bpmn:Gateway');
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(isAny(businessObject, [ 'bpmn:Gateway' ])).to.be.true;
|
||||||
|
expect(isAny(businessObject, [ 'bpmn:SequenceFlow', 'bpmn:Gateway' ])).to.be.true;
|
||||||
|
expect(isAny(businessObject, [ 'bpmn:BaseElement' ])).to.be.true;
|
||||||
|
expect(isAny(businessObject, [ 'bpmn:SequenceFlow' ])).to.be.false;
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('#getDi', function() {
|
describe('#getDi', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user