Skip to content

RFC: Initial spike on as-service architecture - #1

Closed
bajtos wants to merge 7 commits into
masterfrom
feature/initial-spike
Closed

RFC: Initial spike on as-service architecture#1
bajtos wants to merge 7 commits into
masterfrom
feature/initial-spike

Conversation

@bajtos

@bajtos bajtos commented Jan 9, 2014

Copy link
Copy Markdown
Member

This pull request continues the work started in strongloop/loopback-example-access-control#5.

The most significant change is the move from a loopback plugin generating javascript on runtime to a more service-like approach, where we are providing a command-line tool for generating a static services file. This way it will be easier to integrate the generated services file into a minification & bundling workflow (e.g. via Grunt) too.

The generated file includes basic documentation comments based on remote method definitions provided by LoopBack app.

See README.md in the branch for instructions on how to use this new module.

/to @ritch @seanbrookes @Schoonology Please review the solution, whether it's easy to use, also the overall implementation design. There's no need to nit pick about implementation details, most of the code will be thrown away.

/cc @altsang

Miroslav Bajtoš added 7 commits January 9, 2014 07:51
ngdoc comments are the Angular way of writing in-code API documentation.

Tools like docular can process these comments and generate nice HTML
documentation similar to docs.angularjs.org.
lb-ng-doc is a simple CLI tool that allows users to view the API
documentation generated by lb-ng without the need to setup
Grunt project with grunt-docular.
@bajtos

bajtos commented Jan 9, 2014

Copy link
Copy Markdown
Member Author

Replying to @seanbrookes's comment:

  • as I said before it is a little confusing trying to figure out where the factory reference is coming from.
    eg in controllers.js 'loginCtrl' has the following method signature: function($rootScope, $scope, $routeParams, User, $location)
  • It took a little hunting before I realized I needed to look for the angular-resources.js file to find the 'User' factory reference.
  • won't this also affect code helper plugins in developer IDEs? eg: I use WebStorm which has an Angular plugin. If the IDE can't read angular-resources.js it won't be able to provide code hints, etc.

All of this is hopefully resolved, as we are generating a static javascript code now.

  1. how to handle GET requests with the following syntax? http://0.0.0.0:3000/api/dealers?filter[where][location][near]=-122.2577174,49.1499898&filter[limit]=25
Dealers.find(
  {
    filter: {
      where: { location: { near: '-122.2577174,49.1499898' } },
      limit: 25
    }
  },
  // etc.
  1. the model definition seems to suggest the user creation api call should be User.create(); but the code in the controller uses User.save(); this is confusing. It looks like there is a comment in the angular-resources.js file about some hack that adds 'save' to the model prototype, is that what is happening? This is another area where devs can/will get confused.

There are multiple ways of creating a new User.

// 1. The canonical Angular way
// Create a new User instance and call $save
var user = new User({ email: 'foo@bar.com' });
user.address = 'San Mateo';
user.$save();

// 2. An alternative way introduced by LoopBack SDK
// Call static method create
User.create(
  {
    email: 'foo@bar.com',
    // etc.
  },
// handle success & error
);

See also the example in $resource docs.

  1. Angular already has a file in its library called angular-resource.js so this may cause some confusion as well.

Good point. I am using lb-services.js as the default name now.

@Schoonology

Copy link
Copy Markdown

Looking over all the code involved, it makes enough sense to me. You're covering all the bases I'd want to see:

  • Make the services exposed an ng-resource instance.
  • Preserve the ability to call into custom behaviour.
  • Make auth simple.

@bajtos bajtos mentioned this pull request Jan 28, 2014
@bajtos

bajtos commented Jan 28, 2014

Copy link
Copy Markdown
Member Author

Closing in favour of #3.

@bajtos bajtos closed this Jan 28, 2014
@bajtos
bajtos deleted the feature/initial-spike branch January 31, 2014 16:24
@jmls jmls mentioned this pull request Apr 29, 2016
jonathan-casarrubias referenced this pull request in jonathan-casarrubias/loopback-sdk-angular May 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants