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(boot): add helpers to create a booter for component applications #5304

Merged
merged 1 commit into from
May 2, 2020

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented May 1, 2020

Use case:

  • Create a LoopBack application
  • Add controllers, services, datasources
  • Now use this application as a component with the main applicaiton
  • The main application needs to have artifacts from the component application

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • 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
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@raymondfeng raymondfeng requested a review from jannyHou as a code owner May 1, 2020 18:30
@raymondfeng raymondfeng self-assigned this May 1, 2020
@raymondfeng raymondfeng force-pushed the component-app-booter branch 2 times, most recently from 14fa1bb to 38e91de Compare May 1, 2020 20:11
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

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

👍

* Add bindings from the component application to the main application
*/
const bindings = componentApp.find(binding => {
return filter(binding) && !this.mainApp.contains(binding.key);
Copy link
Contributor

Choose a reason for hiding this comment

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

A question for !this.mainApp.contains(binding.key):
what if the sub app wants to override the main app's bindings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are certain bindings from the sub-app should not override the main app. We should carefully review such bindings - for example, CoreBindings.*, RestBindings.*. Maybe one way to solve it is to mark such bindings locked. If so, we can update this code to only skip locked bindings in the main app.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should carefully review such bindings - for example, CoreBindings.*, RestBindings.*

True, agreed. I came up with this question due to the chat happened on public slack this morning, I think that community user tries to contribute custom artifacts(like models, in his case) from the component.

Maybe one way to solve it is to mark such bindings locked. If so, we can update this code to only skip locked bindings in the main app.

I feel it's a case by case preference, maybe we can provide a default filter to skip those core bindings. And if user really wants to override, they provide custom filters :)

(don't have to address it in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I improved the binding filtering as follows:

  • Bindings that exist in the component application before boot are skipped.
  • Locked bindings in the main application will not be overridden.
  • Other bindings are selected by the binding filter. By default, all bindings are picked.

docs/site/Booting-an-Application.md Outdated Show resolved Hide resolved
@raymondfeng raymondfeng force-pushed the component-app-booter branch from 38e91de to f5a6851 Compare May 1, 2020 21:00
Use case:

- Create a LoopBack application
- Add controllers, services, datasources
- Now use this application as a component with the main applicaiton
- The main application needs to have artifacts from the component application
@raymondfeng raymondfeng force-pushed the component-app-booter branch from f5a6851 to e64ad10 Compare May 1, 2020 22:52
@raymondfeng raymondfeng merged commit 9276237 into master May 2, 2020
@raymondfeng raymondfeng deleted the component-app-booter branch May 2, 2020 00:40
@bhupesh-sf
Copy link

Documentation for sub application binding in main application doesn't contain any exmaple. That will be helpful


// This can be done in the constructor of `MainApp` too. Make sure the component
// is registered before calling `app.boot()`.
mainApp.component(SubAppComponent);
Copy link
Member

Choose a reason for hiding this comment

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

@raymondfeng I find these instructions quite involved. Would the following approach work & make sense too?

class MyApp extends BootMixin(Application) {
  constructor(options: ApplicationOptions) {
    super(options);

    this.add(
      createComponentApplicationBooterBinding(new SubApp()),
    );
  }
}

I think it would be great to add a helper method to BootMixin to wrap those two calls in a single API, but I find it difficult to find a good method name. How about addApplicationBooter?

Intended usage:

class MyApp extends BootMixin(Application) {
  constructor(options: ApplicationOptions) {
    super(options);

    this.addApplicationBooter(new SubApp());
  }
}

WDYT?

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.

5 participants