Skip to content

Commit

Permalink
feat(core): Add action declaration and composition
Browse files Browse the repository at this point in the history
Add @action to decorate action classes and methods and use corresponding
metadata to determine the order of invocation so that we can build a
sequence.
  • Loading branch information
Raymond Feng authored and raymondfeng committed Nov 11, 2017
1 parent df1c879 commit 45b2d73
Show file tree
Hide file tree
Showing 13 changed files with 1,381 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/context/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {isPromise} from './is-promise';
* Context provides an implementation of Inversion of Control (IoC) container
*/
export class Context {
private registry: Map<string, Binding>;
protected registry: Map<string, Binding>;

/**
* Create a new context
Expand Down
4 changes: 4 additions & 0 deletions packages/context/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export namespace inject {
bindingKey: string,
metadata?: Object,
) {
metadata = metadata || {};
metadata = Object.assign(metadata, {getter: true});
return inject(bindingKey, metadata, resolveAsGetter);
};

Expand All @@ -149,6 +151,8 @@ export namespace inject {
bindingKey: string,
metadata?: Object,
) {
metadata = metadata || {};
metadata = Object.assign(metadata, {setter: true});
return inject(bindingKey, metadata, resolveAsSetter);
};
}
Expand Down
11 changes: 10 additions & 1 deletion packages/context/test/acceptance/class-level-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {Context, inject, Setter, Getter} from '../..';
import {
Context,
inject,
Setter,
Getter,
describeInjectedArguments,
} from '../..';

const INFO_CONTROLLER = 'controllers.info';

Expand Down Expand Up @@ -157,6 +163,9 @@ describe('Context bindings - Injecting dependencies of classes', () => {
constructor(@inject.setter('key') public setter: Setter<string>) {}
}

const injections = describeInjectedArguments(Store);
expect(injections.length).to.eql(1);
expect(injections[0].metadata!.setter).to.be.true();
ctx.bind('store').toClass(Store);
const store = ctx.getSync('store');

Expand Down
4 changes: 3 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
},
"devDependencies": {
"@loopback/build": "^4.0.0-alpha.5",
"@loopback/testlab": "^4.0.0-alpha.14"
"@loopback/testlab": "^4.0.0-alpha.14",
"@types/uuid": "^3.4.2",
"uuid": "^3.1.0"
},
"files": [
"README.md",
Expand Down
Loading

0 comments on commit 45b2d73

Please sign in to comment.