-
Notifications
You must be signed in to change notification settings - Fork 73
Support loading of mixins #33
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
Conversation
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
+1 thanks :) On Wed, Aug 6, 2014 at 2:49 PM, slnode [email protected] wrote:
-----BEGIN PGP PUBLIC KEY BLOCK----- mQENBFEY1PEBCADPOfERF2wo4qeoq9L1m2z4pKfWqNd4B6BsoFUWPNd7BXmY+9JG |
|
@raymondfeng I've updated this to be in line with: |
|
@fabien could you please rebase on top of current master, clean up the commit history and |
|
@raymondfeng @ritch I'd like to review this patch myself, please don't merge until I approve it. |
|
@bajtos note that this depends on Juggler PR loopbackio/loopback-datasource-juggler#229 |
|
I am afraid loopbackio/loopback-datasource-juggler#201 contains code that does not belong to datasource juggler and should be part of loopback-boot instead. See comment1 and discussion. @fabien Please fix that issue before proceeding with this pull request. |
|
@bajtos see https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/mixins.js it's already fixed AFAIK |
You are right. I'll resume the review then. |
lib/compiler.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read this correctly, you have renamed options.bootDirs to options.bootSources. What is the purpose? It is also not captured in the documentation provided by index.js. Worst of all, it is a breaking change. Could you please revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so I forgot to update the docs in index.js - but wouldn't you agree that it doesn't make any sense to have modelSources (a list of directories) but not bootSources? why would you have a different suffix for this option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the meaning of different suffixes:
modelSourceslists places where to look for models, not all files are requiredbootDirslists directories where all files are loadedbootScriptslists a files that should be added to the list of boot scripts
To stay consistent with this convention, mixins should use mixinDirs and mixinScripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, Sources suffix is used for locations where only some files are picked from, while Dir is used for locations where all files should be picked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind creating a new naming convention, as long as it clearly distinguishes those two scenarios and backward compatibility is preserved (e.g. my marking the old property name as deprecated).
|
Moving the discussion from loopbackio/loopback-datasource-juggler#229
I see two possible solutions:
Thoughts? |
|
I think we should implement both. And the flag should also apply to model name normalizations. |
In which case it may make sense to use one flag for both mixins and models. E.g. Implementing model name normalization is out of scope of this pull request though. |
|
@bajtos @raymondfeng I'll let you guys figure that one out ;-) all I can say is that I'm still not happy with the fact that model names, and more specifically url paths (see strongloop/strong-remoting#90) are not really normalized consistently, or at least promoted as a best practice. |
|
Hi @fabien, what is the status of this pull request? I see these major items that needs to be solved:
Is there anything else I left out? Or is there a way how to split the work into multiple smaller changes, so that this pull request can be landed sooner? |
|
@fabien ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lines seems redundant to me, as any whitespace should have been already processed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which line exactly? and where is the whitespace processed before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this comment, I don't know why I thought whitespace was already removed.
Oh I see, this is more complex. The current implementation always loads all mixins, therefore However, to support isomorphic clients, we need lazy loading of mixins - only mixins that are actually used by the models should be included in the browser bundle. To get that behaviour, we need two things:
My concern is that by supporting Also regarding the second way of defining mixins, via a loopback model object, this should be IMO implemented via a JSON file: // common/mixins/address.json
{
"properties": {
"line1": "string",
"line2": "string",
"city": "string",
"country": "string"
}
}@fabien I understand this may be making the scope too big. IIRC you were using a custom project layout and you needed only the Thoughts? /cc @raymondfeng |
|
Even one more thing: you need to modify bundler too, so that mixin sources are included in the browser bundle. |
Yes, options.mixins is already supported, as is MyModel.mixin('MixinName', { ... }); I'm not familiar with loopback-module - what is it? Same goes for the 'bundler'. Like you said, this adds considerably to the scope of this PR, I think we should open a new one for the remaining client/isomorphic integration. |
In accordance with the latest mixin cleanup in juggler.
Oh sorry, loopback-module should have been loopback-boot. bundler is a part of loopback-boot, see the link in my comment above. I'll respond in more detail next week. |
|
Stepping back a bit and looking at the big picture. IIUC, there are two kinds of mixins:
Mixin as a model loopback-boot already has mechanism for defining arbitrary models, we should reuse this mechanism for defining mixins too. Benefits: developers can apply their knowledge about how to create models to create mixins too. Tools like To support this kind of mixins, we need to extend addAllBaseModels() and sortByInheritance() to take into account mixed-in models in addition to base models. Once that is done, model-like mixins will work both on the server and in the browserified client. Note that this is can be implemented independently (and should be). Mixin as a function This is the part where we need to come up with a new convention. Ultimately, I'd like to see a solution similar to what we have for models, where the compiler understands relations between model definitions and mixin definitions, and can build optimised instructions to load only those mixins that are actually used in the app. Another thing to consider is the new component architecture as outlined here. I am trying to come up with a small solution that can be incrementally extended in next PRs. How about this:
Usage: boot(app, {
appRootDir: __dirname,
mixinScripts: [ './mixins/timestamp.js' ]
});The next step is to implement clever auto-loading of mixins from directories, as described earlier. That way the usage would become To summarise the next steps as I see them now:
Random notes:
|
|
@fabien what is the status of this patch? Are you still up to finish it? |
|
@raymondfeng could you please review my proposal in the comment above too? |
|
@bajtos I can't look into this right now, sorry. All can add is: I don't think the use case of mixing in a Model into another Model isn't really that interesting, to me, it's just an artifact of the past, because these were the only 'mixins' originally supported. |
|
Closing in favour of #79 |
See loopbackio/loopback-datasource-juggler#201