-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The power of mixins #1264
Comments
We would also benefit a lot from this! Would also push for a bigger ecosystem around loopback and make model code modularizable. |
Simply GREAT. Thanks! |
@fabien I like the idea... but this is one of those things that is easy to get wrong. I do appreciate an implemenation that has been used extensively (thats why I think we should start with what you've been using). I'd like to get some usage out of it myself before adopting the programming model. Is it possible extract your mixin implementation into a module? I'd like to incubate something like this outside of core. That way we don't run into similar issues we did with other large feature additions (cough...intent hooks...cough)... |
@ritch this is actually already in core (it lives in juggler mostly), unless I misunderstood your question (about extracting this, so you can use it yourself). It's very lightweight, with few moving parts. |
I also would like to point out that LB |
Cool.
This ^^^^^ ... but in order for us to get there we need to make it easy to create mixins. Perhaps you could open source some genereic mixins you've created @fabien ? In the short term I think we could start with a loopback-example-mixin (modeled after our other examples). /cc @superkhau |
@ritch sure, it might take some time to write isolated tests and things like that, but that shouldn't be a problem once we create a mixin project template (generator?) with such a setup. Note that I would like to preserve the low-level ability of just defining mixins as part of the app itself, instead of forcing |
Sure... but the real draw (IMO, and what interests me) is mixins reusable across apps. Though I don't see that preventing us from supporting per app mixins. |
The way how loopback-boot & loopback-workspace work are designed now, the layout "1 mixin = 1 npm module" is not supported well. Meaning that you can't make an npm module exporting a single Option 1) root-facet layout (requires strongloop/generator-loopback#75)
Option 2) common/client/server layout
These two layout should be eventually supported by loopback-workspace & Of course, user can decide to user any other layout, including an npm module exporting a single |
is there more config required for the syntax mentioned in the first post to work? in order for my mixin (plugin) to work, I need to define it in the LDL file for the model. |
Hi @fabien I'm trying to add a default scope in a mixin without success. Did you create a mixin which contains a defaultScope? I need to add this via mixin "scope": {
"include": [
{
"relation": "children",
"scope": {
"where": {
"parentId": {
"neq": null
}
}
}
}
]
} |
@emresebat - I know this is an old ticket, did you ever find a solution? |
@jbcpollak sorry to tell but no, I gave up eventually. I found loopback to be a good alternative for API development in the beginning and still use it for production apps but I think there are some points that needs to be fixed. |
I'm just throwing this in here to fuel some much needed discussion regarding the state of mixins, and what they could do for Loopback. I'm already using them extensively in my projects, and they allow distinct
traits
to be easily shared amongst models, and to be configured as needed.When I see something like this #1260 - I see a problem that just begs for a Mixin to be implemented. Given the right infrastructure like the new operation hooks, there's a lot you can do.
Most of this has been available since loopbackio/loopback-datasource-juggler#201 ... but there's a pending discussion here: strongloop/loopback-boot#79
This is a bit from an model I've been using in one of my projects,
post.js
:And the
post.json
:Note that there's no pseudo code in there - this all works, and has been tested extensively.
Alternatively, you can declare mixins in your
post.json
under themixins
key like this:The text was updated successfully, but these errors were encountered: