Movatterモバイル変換


[0]ホーム

URL:


Objection.js

# Plugins

A curated list of plugins and modules for objection. Only plugins that followthe best practices are accepted on this list. Other modules like plugins for other frameworks and things that cannot be implemented following the best practices are an exception to this rule. If you are a developer of or otherwise know of a good plugin/module for objection, please create a pull request or an issue to get it added to this list.

# 3rd party plugins

# Other 3rd party modules

# Plugin development best practices

When possible, objection.js plugins should be implemented asclass mixins(opens new window). A mixin is simply a function that takes a class as an argument and returns a subclass. Plugins should not modifyobjection.Model,objection.QueryBuilder or any other global variables directly. See theexample plugin(opens new window) for more info. There is alsoanother example(opens new window) that should be followed if your plugin takes options or configuration parameters.

Mixin is just a function that takes a class and returns an extended subclass.

functionSomeMixin(Model){// The returned class should have no name. That way// the superclass's name gets inherited.returnclassextends Model{// Your modifications.};}

Mixins can be then applied like this:

classPersonextendsSomeMixin(Model){}

Thisdoesn't work since mixins never modify the input:

// This does absolutely nothing.SomeMixin(Model);classPersonextendsModel{}

Multiple mixins:

classPersonextendsSomeMixin(SomeOtherMixin(Model)){}

There are a couple of helpers in objection main module for applying multiple mixins.

const{ mixin, Model}=require('objection');classPersonextendsmixin(Model,[  SomeMixin,  SomeOtherMixin,  EvenMoreMixins,  LolSoManyMixins,ImAMixinWithOptions({foo:'bar'})]){}
const{ compose, Model}=require('objection');const mixins=compose(  SomeMixin,  SomeOtherMixin,  EvenMoreMixins,  LolSoManyMixins,ImAMixinWithOptions({foo:'bar'}));classPersonextendsmixins(Model){}

Mixins can also be used as decorators:

@SomeMixin@MixinWithOptions({foo:'bar'})classPersonextendsModel{}

Documents Contribution guide


[8]ページ先頭

©2009-2025 Movatter.jp