Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LoopBack 3 with Mixins as First Class Citizens

LoopBack 3

Core + Boot + Connector refactor

0. setup

  • all components loaded into registry
  • all mixins loaded into registry
  • registry mixins applied
  • create models, apply model configs, etc
  • create data sources
// applying registry mixins
registryMixins.forEach(function(registryMixin) {
  // loading data sources, models, etc will be implemented as mixins
  registryMixin(registry);
});

1. base mixins

var baseMixin = registry.getMixin(ModelCtor.settings.base);

// these mixins may apply other mixins
// eg. PersistedModelMixin would cobble together
// - DataAccess
// - Validation
// - Find
baseMixin(ModelCtor);

2. ds mixins

var dsMixin = registry.getMixin(ModelCtor.settings.dataSource);
dsMixin(ModelCtor);

3. user defined mixins

ModelCtor
  .settings
  .mixins
  .map(registry.getMixin)
  .forEach(execMixin);

4. global user defined mixins

registry.globalMixins.forEach(function(mixinDesc) {
  if (mixinDesc.shouldBeAppliedTo(ModelCtor)) {
    mixinDesc.mixin(ModelCtor);
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.