Skip to content

Commit a74d423

Browse files
committed
refacto workflow api
1 parent 2ec3dec commit a74d423

File tree

4 files changed

+56
-57
lines changed

4 files changed

+56
-57
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@
6464
"karma-mocha": "^1.3.0",
6565
"karma-script-launcher": "^1.0.0",
6666
"load-grunt-tasks": "^3.5.2",
67-
"mocha": "^5.1.0"
67+
"mocha": "^5.1.1"
6868
}
6969
}

src/component.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ function addOn(Class, classId) {
16361636
}
16371637

16381638
if (
1639-
$workflow.checkParams({
1639+
$workflow.checkInput({
16401640
component: this,
16411641
methodName: 'on',
16421642
args: arguments
@@ -1655,7 +1655,7 @@ function addOn(Class, classId) {
16551655
) {
16561656
$log.behaviorNotUnique(classId, state);
16571657
} else {
1658-
if ($workflow.validParamNumbers(classId, state, action)) {
1658+
if ($workflow.checkInputNumbers(classId, state, action)) {
16591659
behaviorId = $behavior.add(
16601660
this.id(),
16611661
state,
@@ -1716,7 +1716,7 @@ function addOnClass(Class, classId) {
17161716
isCore = true;
17171717
}
17181718
if (
1719-
$workflow.checkParams({
1719+
$workflow.checkInput({
17201720
component: this,
17211721
methodName: 'on',
17221722
args: arguments
@@ -1735,7 +1735,7 @@ function addOnClass(Class, classId) {
17351735
) {
17361736
$log.behaviorNotUnique(classId, state);
17371737
} else {
1738-
if ($workflow.validParamNumbers(classId, state, action)) {
1738+
if ($workflow.checkInputNumbers(classId, state, action)) {
17391739
behaviorId = $behavior.add(
17401740
this.id(),
17411741
state,
@@ -1782,7 +1782,7 @@ function addOnClass(Class, classId) {
17821782
function addOffClass(Class, classId) {
17831783
var proxy = function proxy(state, behaviorId) {
17841784
if (
1785-
$workflow.checkParams({
1785+
$workflow.checkInput({
17861786
component: this,
17871787
methodName: 'off',
17881788
args: arguments

src/system/system-runtime.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/workflow.js

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -251,50 +251,6 @@ function getParamTypes(id, methodName) {
251251
return result;
252252
}
253253

254-
/**
255-
* @method checkResult
256-
* @param {Object} params
257-
* @returns {Boolean} true if conditions on ouput are compliant with the metamodel
258-
* @private
259-
* @description Check if conditions on output are compliant with the metamodel
260-
*/
261-
function checkResult(params) {
262-
params = params || {};
263-
264-
var component = params.component || null;
265-
var methodName = params.methodName || '';
266-
var methodResult = null;
267-
var componentClassName = '';
268-
var returnType = null;
269-
var result = true;
270-
271-
if (typeof params.methodResult !== 'undefined') {
272-
methodResult = params.methodResult;
273-
} else {
274-
methodResult = undefined;
275-
}
276-
277-
if (component.constructor.name === 'Function') {
278-
componentClassName = component.name;
279-
} else {
280-
componentClassName = component.constructor.name;
281-
}
282-
283-
returnType = getReturnType(componentClassName, methodName);
284-
if (!$metamodel.isValidType(methodResult, returnType)) {
285-
result = false;
286-
$log.invalidResultType(
287-
component.id(),
288-
component.constructor.name,
289-
methodName,
290-
JSON.stringify(returnType),
291-
Array.isArray(methodResult) ? 'array' : typeof methodResult
292-
);
293-
}
294-
295-
return result;
296-
}
297-
298254
/**
299255
* @method getActions
300256
* @param {Object} component a System Runtime component
@@ -464,14 +420,14 @@ function action(component, state, action, params, isEvent) {
464420
/* Public methods */
465421

466422
/**
467-
* @method validParamNumbers
423+
* @method checkInputNumbers
468424
* @param {String} className name the class
469425
* @param {String} state state on which the action applied
470426
* @param {Function} action action
471427
* @returns {Boolean} true if the action is the valid number of parameters
472428
* @description Check if an action has the valid number of parameter
473429
*/
474-
exports.validParamNumbers = function validParamNumbers(
430+
exports.checkInputNumbers = function checkInputNumbers(
475431
className,
476432
state,
477433
action
@@ -545,12 +501,12 @@ exports.validParamNumbers = function validParamNumbers(
545501
};
546502

547503
/**
548-
* @method checkParams
504+
* @method checkInput
549505
* @param {Object} params
550506
* @returns {Boolean} true if condition on input are compliant with the model
551507
* @description Check if conditions on input are compliant with the model before calling the action
552508
*/
553-
exports.checkParams = function checkParams(params) {
509+
exports.checkInput = function checkInput(params) {
554510
params = params || {};
555511

556512
var component = params.component || null;
@@ -668,6 +624,49 @@ exports.checkParams = function checkParams(params) {
668624
return result;
669625
};
670626

627+
/**
628+
* @method checkOutput
629+
* @param {Object} params
630+
* @returns {Boolean} true if conditions on ouput are compliant with the metamodel
631+
* @description Check if conditions on output are compliant with the metamodel
632+
*/
633+
exports.checkOutput = function checkOutput(params) {
634+
params = params || {};
635+
636+
var component = params.component || null;
637+
var methodName = params.methodName || '';
638+
var methodResult = null;
639+
var componentClassName = '';
640+
var returnType = null;
641+
var result = true;
642+
643+
if (typeof params.methodResult !== 'undefined') {
644+
methodResult = params.methodResult;
645+
} else {
646+
methodResult = undefined;
647+
}
648+
649+
if (component.constructor.name === 'Function') {
650+
componentClassName = component.name;
651+
} else {
652+
componentClassName = component.constructor.name;
653+
}
654+
655+
returnType = getReturnType(componentClassName, methodName);
656+
if (!$metamodel.isValidType(methodResult, returnType)) {
657+
result = false;
658+
$log.invalidResultType(
659+
component.id(),
660+
component.constructor.name,
661+
methodName,
662+
JSON.stringify(returnType),
663+
Array.isArray(methodResult) ? 'array' : typeof methodResult
664+
);
665+
}
666+
667+
return result;
668+
};
669+
671670
/**
672671
* @method process
673672
* @param {Object} params params to process
@@ -768,7 +767,7 @@ exports.process = function process(params) {
768767

769768
if (actions.length) {
770769
if (
771-
exports.checkParams({
770+
exports.checkInput({
772771
component: component,
773772
methodName: params.state,
774773
args: params.data
@@ -783,7 +782,7 @@ exports.process = function process(params) {
783782
false
784783
);
785784

786-
checkResult({
785+
exports.checkOutput({
787786
component: component,
788787
methodName: params.state,
789788
methodResult: result

0 commit comments

Comments
 (0)