Skip to content

Instantly share code, notes, and snippets.

@ritch
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/e1bede0aca745df94b3d to your computer and use it in GitHub Desktop.
Save ritch/e1bede0aca745df94b3d to your computer and use it in GitHub Desktop.
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