docs: booting in LB3 vs LB4#5178
Conversation
9bc3e7e to
3d518e2
Compare
| ### In LoopBack 4 | ||
|
|
||
| In LoopBack 4, the booting tasks are shared between the | ||
| [RestApplication](./apidocs/apidocs.rest.restapplication.html) class |
There was a problem hiding this comment.
What part of booting does RestApplication handle?
There was a problem hiding this comment.
We should mention it's possible to plug in new types of booters.
There was a problem hiding this comment.
Can we have link to https://loopback.io/doc/en/lb4/Booting-an-Application.html?
There was a problem hiding this comment.
What part of booting does RestApplication handle?
The config part.
There was a problem hiding this comment.
I don't think RestApplication is handling the config part, isn't this handled by Application from @loopback/core? AFAIK, RestApplication is a thin wrapper around Application that's adding a single REST server instance and convenience methods for accessing that server.
Let's build a better understanding of what you are trying to describe, @hacksparrow, and how is that actually implemented.
There was a problem hiding this comment.
So refer to Application of @loopback/core instead? We need to tell where the app configuration is applied as part of the booting process.
There was a problem hiding this comment.
@raymondfeng I have updated accordingly.
| Models are determined from application options or model files, | ||
| [mixins](https://loopback.io/doc/en/lb3/Defining-mixins.html) are applied, | ||
| and they are attached to their respective datasources. They are then attached | ||
| to the LoopBack Application object. |
There was a problem hiding this comment.
FYI: In the first step, we define all models. In the second step, we attach the models to datasources and the application.
The list of models defined may be longer than the list of models attached:
- loopback-boot looks at
server/model-configto see which files should be added to the app. - Then it examines inheritance and mixin configurations, to determine dependencies (which models to add to the list)
- Models are sorted topologically based on inheritance, so that we define parent models before children.
- All models from the list above are defined via model registry.
- Only models specified in
server/model-configare added to the app and attached to a datasource (unlessdataSourceflag is set tonull).
loopback-boot also supports universal mode, where the entire loopback application is bundled for browser. In that case, the boot process is split in two parts:
- The first step finds out which models (and their parents, etc.) are needed by the app. It creates "instructions" for booting an app, these instructions are compiled into the browser bundle together with model source files (
common/models/{model-name}.json). - The second step is performed in the browser, it processes the instructions from the first step.
There was a problem hiding this comment.
Maybe not worth getting into all those details for something that we are moving away from. Especially since the corresponding step in LB4 is an import.
| ### In LoopBack 4 | ||
|
|
||
| In LoopBack 4, the booting tasks are shared between the | ||
| [RestApplication](./apidocs/apidocs.rest.restapplication.html) class |
There was a problem hiding this comment.
I don't think RestApplication is handling the config part, isn't this handled by Application from @loopback/core? AFAIK, RestApplication is a thin wrapper around Application that's adding a single REST server instance and convenience methods for accessing that server.
Let's build a better understanding of what you are trying to describe, @hacksparrow, and how is that actually implemented.
|
|
||
| There is no `config.json` in LoopBack 4. The application options are passed in | ||
| the constructor of the | ||
| [RestApplication](./apidocs/apidocs.rest.restapplication.html) class. |
There was a problem hiding this comment.
Using RestApplication is not mandatory, people can use the base Application class too. This will become more and more important as we add support for different API flavors (gRPC, event-stream consumers, etc.)
| Datasources in LoopBack 3 are defined in a single `datasources.json` file. In | ||
| LoopBack 4, datasources are defined as TypeScript classes that come with an | ||
| associated JSON configuration file. They all reside in the `src/datasources` | ||
| directory. |
There was a problem hiding this comment.
Please note that we are moving away from JSON config files for datasources, see #5000
| associated JSON configuration file. They all reside in the `src/datasources` | ||
| directory. | ||
|
|
||
| `BootMixin` resolves the datasources, and attaches them to the application. |
There was a problem hiding this comment.
Do we have any documentation on how is the datasource booter working under the hood? For example, what files it looks for, how it decided which exported member of a datasource TS file it will add to the app, etc. If yes, then please add a link to it.
There was a problem hiding this comment.
We don't have anything in-depth, AFAIK. The closest is https://loopback.io/doc/en/lb4/Booting-an-Application.html#controller-booter, added the link.
| ### 3. Definition of models | ||
|
|
||
| Although REST APIs are built around Models, they are not a part of the booting | ||
| process in LoopBack 4; Controllers and Repositories are. |
There was a problem hiding this comment.
Can you please briefly explain why we are not booting models?
The main reason is that we need Models at compile time, therefore they must be imported directly.
| process in LoopBack 4; Controllers and Repositories are. | ||
|
|
||
| Controllers and Repositories import models as regular TypeScript classes. | ||
|
|
There was a problem hiding this comment.
Can you please briefly explain why we are not booting models?
The main reason is that we need Models at compile time, because as you have correctly pointed out, controllers and repositories are importing them directly.
aa01187 to
bde8541
Compare
| [loopback-boot](https://github.com/strongloop/loopback-boot), | ||
| which performs the following tasks: | ||
|
|
||
| ### In LoopBack 3 |
There was a problem hiding this comment.
I feel this paragraph
The booting process in LoopBack 3 is handled by
loopback-boot,
which performs the following tasks:
should be under ### In LoopBack 3, instead of before it.
| and the | ||
| [@loopback/boot](./apidocs/apidocs.boot.html) package. Since your application | ||
| will extend `BootMixin` and `Application`, their separation will not be | ||
| apparent to you, and understanding of how they work together as one as not |
There was a problem hiding this comment.
| apparent to you, and understanding of how they work together as one as not | |
| apparent to you, and understanding of how they work together as one is not |
|
|
||
| There is no `config.json` in LoopBack 4. The application options are passed in | ||
| the constructor of the | ||
| [Application](./apidocs/apidocs.core.application.md) class. |
There was a problem hiding this comment.
it'd be better to include a sample code, or the link https://loopback.io/doc/en/lb4/Application.html#configuring-your-application
bajtos
left a comment
There was a problem hiding this comment.
Thank you @hacksparrow for the updates.
Please make sure all relative links are still working after you moved the file to docs/site/migration.
Also #5000 has been landed earlier today, please update the text accordingly.
| {% include note.html content="We are moving away from JSON files for datasource | ||
| configuration. Refer to | ||
| [loopback-next#5000](https://github.com/strongloop/loopback-next/pull/5000) | ||
| for the progress." %} |
There was a problem hiding this comment.
The PR has been already landed, please update this section to reflect the current master.
|
|
||
| `BootMixin` resolves the datasources, and attaches them to the application. | ||
| Read more about datasource booter | ||
| [here](./Booting-an-Application.md#controller-booter). |
There was a problem hiding this comment.
Did you update all links after moving the file to docs/site/migration? I don't think this link is valid now.
| [here](./Booting-an-Application.md#controller-booter). | ||
|
|
||
| Read more about LoopBack 4 datasource [here](./DataSources.md). | ||
|
|
There was a problem hiding this comment.
Should we add a link to https://loopback.io/doc/en/lb4/migration-datasources.html too?
| for modularly adding functionality to the framework. Controllers, Repositories, | ||
| Datasources, Interceptors, etc., are added using booters, custom booters can | ||
| be written for adding new functionality to the framework." %} | ||
|
|
There was a problem hiding this comment.
Should we add a link to https://loopback.io/doc/en/lb4/migration-models-overview.html?
| refer to the | ||
| [booting documentation](./Booting-an-Application.md)." %} | ||
|
|
||
| ### 1. Configuration of application settings |
There was a problem hiding this comment.
Should this and the two below be fourth-level headings?
There was a problem hiding this comment.
Indeed. Thanks.
| Read more about datasource booter | ||
| [here](./Booting-an-Application.md#controller-booter). | ||
|
|
||
| Read more about LoopBack 4 datasource [here](./DataSources.md). |
There was a problem hiding this comment.
Nitpick: datasource -> datasources
|
|
||
| If you want to mount an Express router in a LoopBack 4 application, you can use | ||
| the | ||
| [RestApplication.mountExpressRouter()](./apidocs/apidocs.rest.restapplication.mountexpressrouter.md) |
There was a problem hiding this comment.
Can we link to https://loopback.io/doc/en/lb4/Routes.html#mounting-an-express-router instead?
4d2b034 to
5b66456
Compare
|
Thanks @bajtos, fixed them. |
|
@nabdelgadir I have applied your feedback. Can you PTAL? |
Differences in LB3 and LB4 booting.
b35d76b to
92c7347
Compare
Differences in LB3 and LB4 booting. Addresses #4838.