You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Almost all users new to LoopBack SDK for AngularJS get confused about the client API and the fact that the arguments must be passed in a named object. Figuring out how to correctly invoke related methods is even more difficult.
I am proposing to rework the code generator to drop ngResource and produce an API that is as much close to the server-side API as possible.
Note that this is different from the solution proposed in #83. #83 is brining the whole loopback to the browser, while this is modifying the client API produced by our code generator.
/cc @seanbrookes@anthonyettinger@ritch@kraman What's your opinion? Would you prefer to have a client API that is closer to the server API, or do you prefer the current ngResource-based API instead?
Of course, the current ngResource-based API will remain available, the new isomorphic API will be released either as a new major version, or as a different template that can be chosen by the SDK user
Here is a (partial) list of issues and questions caused by this issue:
Would this API have any advantages over the existing angular resource way of doing things?
It will be easier for new developers to learn. I was running a LoopBack+Angular workshop twice and almost everybody got confused about the correct way of using the client API.
It is also a common source of confusion in the mailing list and gitter. People find a documentation page showing the server API and they don't realise they need a different API in the client. There are no warnings nor error messages to help them easily figure out their mistake.
Perhaps make bi-dir sync easier?
No, you need the full loopback app for offline sync, at least at the moment. See #83 for that.
+1 I think there's room for both this issue and #83. I went through loopback, promisified everything on the client, and wired in to an Angular app. It actually worked pretty well. Used the find -> findAsyc method of naming. The best thing about it was validation on the client side worked out of the box.
But I ended up dropping this and going with the Angular SDK instead. Angular SDK is much more light-weight (significantly smaller file download size) so perfectly workable for most applications.
That being said, the documentation is pretty bad and it's hard to determine what methods take as their parameters. I've been using it for a few weeks and I'm still not quite sure the right way to call a .link() function between two HasManyThrough relation objects.
But the API you are proposing above is quite a bit better than using ngResource. It would look and feel a lot more like server-side code, while still wiring in to Angular easily.
One recommendation would be to make the core code non-Angular specific. Then an add-on which takes the core and wires it into the digest cycle for Angular.
@kraman if size is the major concern in the #83, I'm wonder if it makes sense to try and optimize that bundle and automatically get all the advanced LB features.
See strongloop/loopback#989 (comment). I don't think it's possible to reduce the size of the browserified bundle to a similar order of magnitude that can be achieved with a thin code-generated client. Just four core files (dao, datasource, relation-definition, persisted-model) contain ~250kb of un-minified source code, not including any dependencies.
Having said that, reducing the size of browserified bundle is still important, regardless on the decision made about the proposal discussed here.
@jasonaden That being said, the documentation is pretty bad and it's hard to determine what methods take as their parameters.
Are you referring to the ngdoc comments generated by the code generator, which can be viewed e.g. using docular via lb-ng-doc? How can we improve these comments to make it more clear what are method arguments?
I've been using it for a few weeks and I'm still not quite sure the right way to call a .link() function between two HasManyThrough relation objects.
Considering recent development, where AngularJS 1.x have been superseded by Angular 2+, and LoopBack 2.x/3.x is going to be superseded by LoopBack 4 (a.k.a Next), I don't see how this will ever become a priority for us. I am closing this issue.
If there is anybody interested in making this happen, then I think the best option is to fork this repository and create a new npm package.
Activity
kraman commentedon Mar 16, 2015
Would this API have any advantages over the existing angular resource way of doing things? Perhaps make bi-dir sync easier?
bajtos commentedon Mar 16, 2015
It will be easier for new developers to learn. I was running a LoopBack+Angular workshop twice and almost everybody got confused about the correct way of using the client API.
It is also a common source of confusion in the mailing list and gitter. People find a documentation page showing the server API and they don't realise they need a different API in the client. There are no warnings nor error messages to help them easily figure out their mistake.
No, you need the full loopback app for offline sync, at least at the moment. See #83 for that.
jasonaden commentedon Apr 5, 2015
+1 I think there's room for both this issue and #83. I went through loopback, promisified everything on the client, and wired in to an Angular app. It actually worked pretty well. Used the
find -> findAsycmethod of naming. The best thing about it was validation on the client side worked out of the box.But I ended up dropping this and going with the Angular SDK instead. Angular SDK is much more light-weight (significantly smaller file download size) so perfectly workable for most applications.
That being said, the documentation is pretty bad and it's hard to determine what methods take as their parameters. I've been using it for a few weeks and I'm still not quite sure the right way to call a .link() function between two HasManyThrough relation objects.
But the API you are proposing above is quite a bit better than using ngResource. It would look and feel a lot more like server-side code, while still wiring in to Angular easily.
One recommendation would be to make the core code non-Angular specific. Then an add-on which takes the core and wires it into the digest cycle for Angular.
kraman commentedon Apr 6, 2015
@jasonaden @bajtos I can see the advantage of this proposal, but if size is the major concern in the #83, I'm wonder if it makes sense to try and optimize that bundle and automatically get all the advanced LB features. Specially considering something like http://blog.npmjs.org/post/114584444410/using-angulars-new-improved-browserify-support
bajtos commentedon Apr 7, 2015
See strongloop/loopback#989 (comment). I don't think it's possible to reduce the size of the browserified bundle to a similar order of magnitude that can be achieved with a thin code-generated client. Just four core files (dao, datasource, relation-definition, persisted-model) contain ~250kb of un-minified source code, not including any dependencies.
Having said that, reducing the size of browserified bundle is still important, regardless on the decision made about the proposal discussed here.
Are you referring to the ngdoc comments generated by the code generator, which can be viewed e.g. using docular via
lb-ng-doc? How can we improve these comments to make it more clear what are method arguments?I think you have run into a known issue, see #78.
glesage commentedon Jul 26, 2015
Thanks for all solutions!
Since I didn't clearly understand why passing
nullfixed the issue, here's for others who want to know:the reason why @mikamboo 's solution in #145 works is because passing
nullremoves theidparameter that gets automatically passed to any request...Ex:
Car.tags.link({id:carID, fk:tagID})would actually create a TagCars row in the datasource as such:id: carId, carId: carId, tagId: tagIdThis might work the first time, if no other TagCars row has this particular ID, but any subsequent calls would fail.. for duplicate PRIMARY ID
bajtos commentedon Jan 25, 2018
Considering recent development, where AngularJS 1.x have been superseded by Angular 2+, and LoopBack 2.x/3.x is going to be superseded by LoopBack 4 (a.k.a Next), I don't see how this will ever become a priority for us. I am closing this issue.
If there is anybody interested in making this happen, then I think the best option is to fork this repository and create a new npm package.