docs/site/migration/components/mixins.md
{% include tip.html content=" Missing instructions for your LoopBack 3 use case? Please report a Migration docs issue on GitHub to let us know. " %}
In LoopBack 3, a component contributes mixins by providing files exporting mixin functions, for example:
// lib/my-mixin.js
module.exports = myMixin(Model, options) {
// modify the target model provided in `Model`
// apply configuration as specified in `options`
};
In LoopBack 4, models are architecturally decoupled into 3 entities (a model, a repository and a controller), as further explained in Migrating models and Migrating custom model methods. As a result, most LoopBack 3 mixins become a set of multiple mixins in LoopBack 4.
To migrate a mixin from a LoopBack 3 component to a LoopBack 4 component:
Follow the steps described in
Migrating model mixins
to convert your mixin implementation to LB4 style. We recommend to put the
new files to src/mixins directory in your LB4 component project.
Modify your LB4 component to export the mixins - add export statements to
components src/index.ts file. For example:
// src/index.ts
export * from './mixins/my-mixin';
Update your documentation to show how to apply the new mixins in LoopBack 4 applications, use the content provided in Migrating model mixins for inspiration.