-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
refactor(rest): use dynamic value provider for actions #5561
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a breaking change to me because AFAICT, FindRouteProvider
is a public API exported by @loopback/rest
. (Strangely enough, other sequence action providers are not exported.)
Please check other touched packages for breaking changes in the public API.
Have you considered preserving current instance-based providers as thin wrappers around the new static providers for backwards compatibility? Maybe it's not worth the effort, let's discuss.
If we are going to make breaking changes, then let's check what other changes to include in the major release please. For example, it would be great to remove support for externally hosted REST API Explorer from @loopback/rest
so bring us closer to shutting down https://explorer.loopback.io
I don't have strong opinions on the actual change from instance providers to static providers, I'll leave that up to code owners to decide (@hacksparrow @emonddr @deepakrkris). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first time I am seeing static value method for providers. Just wondering: 1) the strategic reason for making them static, and 2) how this will affect existing applications using components affected by this change.
That's probably not worth the effort. Too many choices are bad :-). |
0d5e551
to
5b6a1ce
Compare
5b6a1ce
to
26bc0b5
Compare
26bc0b5
to
6ecd5bc
Compare
1fcaf2b
to
68b6631
Compare
That's true 👍 Please update the commit message to communicate this change as backwards-incompatible. |
I'll leave the review in the hands of code owners.
dab0860
to
fbe8fd2
Compare
fbe8fd2
to
40b52c6
Compare
@jannyHou @hacksparrow Please review. |
40b52c6
to
5692a84
Compare
export class SendProvider implements Provider<Send> { | ||
value() { | ||
export class SendProvider { | ||
static value() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessarily in this PR, can we also turn SendResponseMiddlewareProvider
into a static Provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed as SendResponseMiddlewareProvider
is a singleton.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raymondfeng the previous SendProvider
is also a singleton...
5692a84
to
ad6173b
Compare
static value( | ||
@inject(RestBindings.Http.CONTEXT) context: Context, | ||
): InvokeMethod { | ||
const invokeMethod: InvokeMethod = (route, args) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types for route
and args
are missing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are inferred from InvokeMethod
type.
@inject(RestBindings.Http.CONTEXT) context: Context, | ||
@inject(RestBindings.HANDLER) handler: HttpHandler, | ||
): FindRoute { | ||
const findRoute: FindRoute = request => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: missing Request
type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's inferred from FindRoute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the benchmark this PR would have a significant improvement for request processing 👍
A few nitpicks and please fix the lint.
BREAKING CHANGE: If you use one of the built-in action providers as the base class, this commit will break you as the signature of the base class has changed. Otherwise the code should be backward compatible for existing applications. Signed-off-by: Raymond Feng <[email protected]>
ad6173b
to
eac9a22
Compare
This one is minor improvement. |
Optimize actions using static providers.
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈