Reputation: 1221
Sometimes it happens that a class we want to extend is not a part of Spartacus' public API. Therefore we cannot import directly SomeClass
from @spartacus/xxxxx
.
We already found or created a github issue with a proposal to export SomeClass
in the public API. Now waiting for the response from the Spartacus core team.
What can we do in the meantime if we really need to import it and extend in our project?
Upvotes: 1
Views: 322
Reputation: 1221
When you need a private API member of Spartacus, please first:
Disclaimer: The private API of Spartacus should not be used in general. It may change at any time without any warning. You can use the following workaround on your OWN RISK. It might result in breaking your code after upgrading to any next version.
Open file node_modules/@spartacus/xxxxx/spartacus-xxxxx.d.ts
and find the exported alias name for the class, prefixed with symbol ɵ
:
export { SomeClass as ɵxyz } from '..........';
Then you can use the alias in your application, for example to extend the class behavior:
import { ɵxyz as SomeClass } from `@spartacus/core`;
/* ... */
// for example:
@Injectable()
export class CustomSomeClass extends SomeClass {
/*...*/
}
/* ... */
@NgModule({
providers: [
{ provide: SomeClass, useClass: CustomSomeClass }
]
})
WARNING: the ɵ
-alias might change in any next release of Spartacus without any warning. It's not a part of the public API.
Upvotes: 6