Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit 67b9b5c

Browse files
committed
feat: StepProviderMixin()
1 parent 968a798 commit 67b9b5c

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
},
3232
"devDependencies": {
3333
"ava": "^0.24.0",
34+
"babel-preset-env": "^1.6.1",
3435
"jsdoc-babel": "^0.3.0",
3536
"jsdoc-to-markdown": "^3.0.2",
3637
"kronos-service-manager": "^3.5.10",
3738
"kronos-test-step": "3.1.4",
3839
"markdown-doctest": "^0.9.1",
3940
"nyc": "^11.4.0",
4041
"rollup": "^0.52.1",
42+
"rollup-plugin-multi-entry": "^2.0.2",
4143
"semantic-release": "^10.0.1",
42-
"xo": "^0.19.0",
43-
"babel-preset-env": "^1.6.1"
44+
"xo": "^0.19.0"
4445
},
4546
"contributors": [
4647
{

src/step-provider-mixin.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { defineRegistryProperties } from 'registry-mixin';
2+
3+
/**
4+
* Provide steps.
5+
*/
6+
export function StepProviderMixin(superclass) {
7+
return class extends superclass {
8+
/**
9+
* if config is an array entry 0 then entry 0 will be passed to super and all other entries
10+
* are handed over as initial config to the config services
11+
*/
12+
constructor(...args) {
13+
super(...args);
14+
15+
defineRegistryProperties(this, 'stepFactory', {
16+
pluralName: 'stepFactories',
17+
withCreateInstance: true,
18+
withEvents: true,
19+
factoryType: 'new'
20+
});
21+
}
22+
23+
declareStep(config, owner) {
24+
return this.createStepFactoryInstanceFromConfig(config, owner);
25+
}
26+
};
27+
}

tests/rollup.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import multiEntry from 'rollup-plugin-multi-entry';
2+
13
export default {
2-
input: 'tests/step-test.js',
4+
input: 'tests/**/*-test.js',
35
output: {
46
file: 'build/step-test.js',
57
format: 'cjs',
@@ -12,5 +14,5 @@ export default {
1214
'loglevel-mixin',
1315
'model-attributes'
1416
],
15-
plugins: []
17+
plugins: [multiEntry()]
1618
};

tests/step-provider-mixin-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import test from 'ava';
2+
import { Step } from '../src/step';
3+
import { StepProviderMixin } from '../src/step-provider-mixin';
4+
5+
class AStep extends Step {
6+
static get name() {
7+
return 'a-step';
8+
}
9+
}
10+
11+
test('provider', async t => {
12+
const provider = new StepProviderMixin(class {});
13+
14+
provider.registerStep(AStep);
15+
16+
const step = await provider.declareStep(
17+
{
18+
name: 's1',
19+
type: 'a-step'
20+
},
21+
{}
22+
);
23+
24+
t.is(step.name, 's1');
25+
t.is(step.type, 'a-step');
26+
});

0 commit comments

Comments
 (0)