I learned from angular-material and angular-flex-layout that when they export a component, they first export the relevant sub-components in public-api.ts and then just export everything from the public-api.ts in the index.ts (e.g. export * from './public-api'). Here is the example of its badge component:
// public-api.ts
export * from './badge-module';
export * from './badge';
// index.ts
export * from './public-api';
My question is why don't just put all the export things to index.ts but border to create one more public-api.ts?
Angular Flex-Layout is a stand-alone library developed by the Angular team for designing sophisticated layouts. When creating an HTML page in Angular, using Angular Flex-Layout allows us to easily create FlexBox-based page layouts with a set of directives available for use in your templates.
From your project folder, run the following command to install Flex Layout: npm install @angular/flex-layout @10.0. 0-beta. 32.
fxLayout defines the flow of children elements along the main-axis or cross-axis, inside the flex container. Depending upon our layout we can pass four different values to the fxLayout attribute row,column, row-reverse and column-reverse. In addition to the fxLayout accepts other parameters like wrap and inline.
Angular Material's Layout features provide sugar to enable developers to more easily create modern, responsive layouts on top of CSS3 flexbox. The layout API consists of a set of Angular directives that can be applied to any of your application's HTML content.
To keep the code cleaner.
Because 'index' doesn't mean much. But 'public-api' makes it clear what is there, that is, public entities
public_api.ts is intended to enumerate and expose specific functionality for external use. index.ts is intended as a default exporting mechanism to deprecate full-path imports.
Using public_api.ts in libraries instead of piling everything in index.ts
At a glance I think there are several reasons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With