Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds MultiMethodDecoratorFactory #4417

Merged

Conversation

mschnee
Copy link
Contributor

@mschnee mschnee commented Jan 13, 2020

Partially implements: #4300
See: #4406

This has been split from #4406 as a more manageable, smaller PR.

Added

  • MultiMethodDecoratorFactory. This factory supports using multiple decorators on a method, storing and returning the metadata as an array. This is in support of the @response decorator, which will be split from feat: adds several convenience decorators #4406 into a separate pull request.

Examples

import {MethodMultiDecoratorFactory} from '@loopback/metadata';

interface Point {
  x?: number;
  y?: number;
  z?: number;
}

function myMultiMethodDecorator(spec: Point): MethodDecorator {
  return MethodMultiDecoratorFactory.createDecorator<Point>(
    'metadata-key-for-my-method-multi-decorator',
    spec,
  );
}

class MyController {
  @myMultiMethodDecorator({x: 1})
  @myMultiMethodDecorator({y: 2})
  @myMultiMethodDecorator({z: 3})
  public point() {}
}

class MyOtherController {
  @myMultiMethodDecorator([{x: 1}, {y: 2}, {z: 3}])
  public point() {}
}

const arrayOfPoints = MetadataInspector.getMethodMetadata<Point>(
  'metadata-key-for-my-method-multi-decorator',
  MyController.prototype,
  'point',
); // [{x:1}, {y:2}, {z: 3}]

const anotherArrayOfPoints = MetadataInspector.getMethodMetadata<Point>(
  'metadata-key-for-my-method-multi-decorator',
  MyOtherController.prototype,
  'point',
); // [{x:1}, {y:2}, {z: 3}]

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • (n/a) Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

.vscode/launch.json Outdated Show resolved Hide resolved
Copy link
Contributor

@raymondfeng raymondfeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mschnee Great addition. Please address my comments.

@mschnee mschnee requested a review from raymondfeng January 14, 2020 21:35
@mschnee
Copy link
Contributor Author

mschnee commented Jan 14, 2020

Updates made- thanks for the quick feedback @raymondfeng !

@mschnee mschnee requested a review from raymondfeng January 14, 2020 23:09
@raymondfeng raymondfeng merged commit d9d8154 into loopbackio:master Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants