-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Problem:
The problem of MixinBuilder from my test is: function with() doesn't set its returned type as a class extends the BaseClass:
click to see test example
let AppWithRepoMixin = class extends MixinBuilder.mix(Application).with(RepositoryMixin){};
const myApp = new AppWithRepoMixin();
const boundComponentsBefore = myApp.find('components.*').map(b => b.key);fails when compiling, because compiler doesn't know myApp is an instance of Application, therefore doesn't know it has a prototype function find() returning an Array. The code calls map with any instead of Array and fails.
This looks like a stop for people wanting to use it...
I am going to defer writing doc for MixinBuilder and create an issue for it. I still love the fluent api and would like to dig more ⭐
Document cut from PR loopbackio/loopback.io#491
Mixin Builder
LoopBack provides a mixin builder function
MixinBuilderto easily extend a class
with one or multiple mixins,
you can call it to define the new extended class with fluent syntaxed API like:
import {MixiBuilder} from '@loopback/repository';
import {BaseClass} from '<path_exports_BaseClass>';
import {FooMixin, BarMixin} from '<path_exports_Mixins>';
let newClass = MixinBuilder.mix(baseClass).with(FooMixin, BarMixin);Acceptance Criteria
-
Move
MixinBuilderclass from@loopback/repositoryto@loopback/core -
Fix
MixinBuilderto return the correct type for class as it currently fails to do so -
Update TSDocs for this Class
-
Tests
-
Bonus: See if this can be just a static method on
Applicationinstead of a new Class as proposed here: Fix and documentMixinBuilder#673 (comment) DO NOT SPEND MORE THAN 1 HOUR on this. Fixing the class is good enough for this task.