-
Notifications
You must be signed in to change notification settings - Fork 83
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
Feature: enable parse of model-config.js for client models extension #84
Feature: enable parse of model-config.js for client models extension #84
Conversation
Hi @pandaiolo, thank you for the pull request. It is a large change, I'll need more time to review it. Few things that stand out on the first read:
I am rather unhappy with the API of the shared methods:
It's not an idiomatic Node.js code, it's not an idiomatic promise-style code. I suppose it is close to the ngResource API when used on the client side, but that does not work at all on the server - We should spend some more time here and come up with a nicer API. Related: |
As for the commit "Fix deprecated express res.send(status,...) calls", can you submit it as a standalone PR please? I am happy to merge that one. |
Seems this is already impemented in this PR, at least according to the comment |
Thanks for reviewing my PR ! About the example in the spec, that I called About |
Here is the problem: at the moment, the usual way is to use ngResource style in the client and Node callbacks on the server. // client
var users = User.find();
users.$promise.then(...)
// server
User.find(function(err, users) { ... }) How can I achieve the same result using the solution proposed in this patch? |
IIRC, the Let's figure out how to improve the API of the shared methods first and defer the implementation details for the next step. |
Ok I understand, yes obviously Angular $resource and LB models behaviours have little in common, and it would be nice if this SDK could be more isomorphic. But isn't this PR on the roadmap? It's only a small step ahead, but it extends the features of current angular sdk in a way developers can take advantage of (Example : I have a Assuming that point of view, couldn't a future hypothetic PR, that would improve isomorphism, do it on top of these features ? It would be some kind of wrapper right ? |
@ritch could you please add your opinion too? |
Related to this PR, some questions I have about the boot process : https://groups.google.com/forum/#!topic/loopbackjs/Ndz_F1NxvY0 |
Wow this is a huge change. Thank you for taking the time to spell it out so clearly. I share the same concerns outlined by @bajtos. My biggest concern is that this directly conflicts with the isomorphic approach which I would like to rebuild the angular SDK on. Can you provide a standalone example (very small) that we can go through? The examples in the test seem a bit too trivial to really see the overlap that I am concerned with. We only now know the size for full stack example after building it, I think the same thing is required here so we don't miss similar issues. Overall I really like this idea and want to find some way to include it, document, and make it easy for people to use. |
Thanks ! I'll give a shot at a demonstrative example this WE or next week. Also, after @bajtos explanation of the boot process, I see that I Not sure if it's clear... however it was when @bajtos explained here : Anyway, the expected structure does not seem technically in conflict with I'll try to put an example together, I let you know 2014-10-22 20:28 GMT+02:00 Ritchie Martori notifications@github.com:
|
@pandaiolo sorry for taking so much time to comment here. I'd like to come up with a way how to break this PR into smaller incremental changes and start landing those that makes most sense. The first step is to implement support for basic
The API for the the code generator and the implementation should be ideally similar to loopback-boot. Instead of passing server app to the generator, it should accept What's your opinion on making this part the first change to get landed? |
Yes this sounds like good first step to me too ! I'll have a look on how loopback-boot implements this. I have another loosely related question about browser SDK as a whole. I discovered angular-data, which looks awesome. It is not as lightweight as $resource, but it's much more featured. Most interesting are models relations, in-memory key-value store for models, with caching mechanism for both individual models and collections, not to mention the firebase-like 3-way data binding. $resource is 4K minified, angular-data 64K, a lot more, but still way more lightweight than full-stack LB payload. My questions :
Interesting notes (after some emails with Jason the developer) :
I feel like this seem completely redundant to the full-stack loopback initiative... However, as an end user, I cannot really know when it will be lightweight enough for production, if it does anytime soon - you earlier said that web clients SDK is not a big priority in SL present efforts (did that include full stack LB?). Context: I am in the middle of a major refactoring of my app which uses Loopback, so I really have to make a call here on which solution I will use in the next weeks that can quickly land into production. |
I don't know anything about angular-data and thus don't have any opinion. @ritch IIRC, you were collaborating on the design of angular data, could you please read the comment above and let us know your thoughts?
IMO, if you have the time to put into developing an alternate SDK based on angular-data, then go for it. If your approach turns out to be good, then we can borrow some of your ideas for the official SDK, or even make your project the official SDK for AngularJS. Even if you discover along the way that angular-data is not the right approach, then at least we will all know we have to look for different solutions. |
* Expects loopback style model-config.json as fourth parameter * Expects `dataSource = "remote"` for REST-exposed models * No backward compatibility break if model-config parameter missing * If model-config present, any model not in the file will be skipped * If model-config present, any model not REST-exposed will be skipped * Look for model.js extension files in `modelConfig._meta.sources` * Expects model.js files to be nodejs modules returning same object as ones expected in the loopback boot process Note : `fixture/model-config.json` contains all models used in the test suite so nothing will break. Only MyModel contains custom logic.
* Some models in the server are not exposed but needed on the client * This enables generation of their Angular service (not resource) * Extention of those object models works the same as REST ones * These need to be declared in model-config with `dataSource: none`
* Client models might need other models/tools as dependency * In the server, model.js files start with `var dep = require('dep');` * The same model.js file will also get its dependencies by declaring them in model-config.json in the `dependencies` property * Example : `dependencies: ['User', '_', '$q']` * Dependencies must already have a provider in Angular ap where lbServices are used * REST resources and static models can have dependencies specified
5ead31d
to
a00ea7e
Compare
@pandaiolo I am not sure what is the status of this PR. I can see new commits, however they still implement more that what I described for the first step. Please leave a comment when the PR is ready for another round of review. |
@pandaiolo could you please provide us with an update? Are you still keen to get this finished? |
I am closing this pull request as it seems to be abandoned. @pandaiolo let us know if you ever find time to finish this work, I am happy to reopen the pull request in such case. |
Yep, ok, I will rebase this branch for me because my app use it, but anyway I need to find some time to propose the first step as a new PR (just parse |
This PR enables
model-config.json
definitions for the angular client ie enables models code sharing within current angular-sdk-clientI implemented this because full-blown browserification (like in loopback-example-full-stack) is a too heavy payload for me, and because
loopback-sdk-angular
works well for me.3 main commits with comments on each of them for the details
List of main features added by each commit
model-config.json
Highlights
Notes
res.send
express method, can remove if out of purposegrunt-loopback-sdk-angular
as well, incoming PRRelated: the issue #24 and a previous attempt on the implementation in #25.