-
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
Should we introduce sugar for bulk app bindings? #990
Comments
loopbackio/loopback.io#619 (review)
|
Personally, I like the REST parameter flavor: app.controller(...controllerCtors); But I don't mind calling the method one by one for each controller as it won't be used by application code so often. app.controller(c1);
app.controller(c2); The above call can be simplified as: [c1, c2].forEach(c => app.controller(c)); |
I don't mind having an arbitrary args list for things ( I know that our boot module is going to take a lot of the manual involvement out of typical wireup, but it's a small amount of effort to provide this sugar for users. That being said, I would like the sugar method to be different ( |
I think getting rid of the optional controller
|
Here is what we can do to support all styles in one signature: /**
* Normalize array or rest parameters into a flat array of arguments
* @param params An array or rest parameters of values. For example,
* - tag('t1') // A single param
* - tag('t1', 't2') // Rest params
* - tag(['t1', 't2']) // A param with array value
* - tag('t1', ['t2', 't3'], 't4') // Mixed usage of values and arrays
*/
export function getArrayOrRestArgs<T>(...params: (T | T[])[]): T[] {
const args: T[] = [];
for (const p of params) {
if (Array.isArray(p)) {
args.push(...p);
} else {
args.push(p);
}
}
return args;
} |
i don't think it should be part of |
+1 for leaving this out of MVP. I am personally fine with the current API allowing only a single value and requiring users to call e.g. I am strongly against having two methods with names that differ only in the singular/plural form ( |
@raymondfeng @shimks @virkt25, @bajtos proposed to close it. What do you think? |
I'd be ok to leave it out of the scope of DP3 (but it's a simple enough experience) ... but I would like for us to implement the |
+1 to support the rest params. |
FWIW, loopback-boot already supports loading components - see https://loopback.io/doc/en/lb3/component-config.json.html. IMO, the fact that components are npm modules should not prevent us from loading them automatically based on conventional configuration, as long as there is a common API for components/extensions. In LoopBack3, the API contract for an extension is to provide a default export that's a function accepting |
We can definitely have a And for custom components in a |
Now we have https://loopback.io/doc/en/lb4/Binding.html#configure-binding-attributes-for-a-class, it makes more sense to allow rest parameters, such as:
|
+1 I think we should also preserve the current API that allows callers to customize the binding without the need to use decorators - this is important for JavaScript consumers for example. app.controller(DefaultCrudCntroller, 'MyControllerName');
app.repository(RepoClass, 'UserRepository');
app.dataSource(DataSourceClass, 'db'); It would be great if somebody can compile a list of APIs (methods) we need to change as part of this story and create a check-list in the acceptance criteria in the issue description. Places where t look:
|
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Currently,
Applications
can only bind their components, controllers, and repositories through callingapp.component
,app.controller
, and so forth. If a user wanted to bind multiple components, they would have to bind them one by one like so:With #742, sugar for accepting array of components were supposed to be added but with
boot
, the sugar may not be necessary anymore.What is our consensus on this issue?
The text was updated successfully, but these errors were encountered: