Giter Site home page Giter Site logo

Comments (7)

hunterloftis avatar hunterloftis commented on June 27, 2024

Of course, since app knows about all of its controllers, we could optionally leave off the controller arg and have:

  app.resource('projects', function() {
    this.resource('pages', function() {
      this.resource('comments');
    });
    this.resource('reviews');
  })
  .map('stats', 'statistics')  // optional second arg if the method name doesn't match the mapped route
  .map('collaborators');

from base12.

hunterloftis avatar hunterloftis commented on June 27, 2024

Here's a comparison with a functional style declaration. Anyone have a strong argument for a preference? I kind of like the functional style because all resources at the same depth are indented the same amount. Also, non-resources that are embedded into the same route (the custom maps like /first/sub1) are on the same level.

  /**
   * should create 26 routes:
   *
   * /first (GET, POST)
   * /first/:first (GET, PUT, DELETE)
   * /first/:first/second (GET, POST)
   * /first/:first/second/:second (GET, PUT, DELETE)
   * /first/:first/second/:second/third (GET, POST)
   * /first/:first/second/:second/third/:third (GET, PUT, DELETE)
   * /first/:first/second/:second/third/innersub (GET)
   * /first/:first/ii (GET, POST)
   * /first/:first/ii/:ii (GET, PUT, DELETE)
   * /first/sub1 (GET, POST, PUT, DELETE)
   * /first/subtwo (POST)
   */

  // A
  app.resource('first', function() {
    this.resource('second', function() {
      this.resource('third').get('innersub');
    });
    this.resource('ii');
  })
  .all('sub1')
  .post('subtwo', 'sub2');

  // B
  app.resource(function(resource) {
    resource('first',
      resource('second',
        resource('third',
          get('innersub')
        )
      ),
      resource('ii'),
      all('sub1'),
      post('subtwo', 'sub2')
    );
  });

from base12.

hunterloftis avatar hunterloftis commented on June 27, 2024

Would love to make it easy to do something like this:

http://weblog.jamisbuck.org/2007/2/5/nesting-resources

from base12.

hunterloftis avatar hunterloftis commented on June 27, 2024

I dig the idea of turning 2-level-max nesting on by default:

  /**
   * /first (GET, POST)
   * /first/:first (GET, PUT, DELETE)
   * /first/:first/second (GET, POST)
   * /second/:second (GET, PUT, DELETE)
   * /second/:second/third (GET, POST)
   * /third/:third (GET, PUT, DELETE)
   * /second/:second/third/innersub (GET) <-- or should it be /third/:third/innersub? Where should mappings go when they're nested?
   * /first/:first/ii (GET, POST)
   * /ii/:ii (GET, PUT, DELETE)
   * /first/sub1 (GET, POST, PUT, DELETE) <-- or should it be /first/:first/sub1?
   * /first/sub2 (POST) <-- ditto
   */

from base12.

katowulf avatar katowulf commented on June 27, 2024

Of course, since app knows about all of its controllers, we could optionally leave off the controller arg and have:

I understand that this is a rails-inspired construct, but couldn't this be taken even one step farther? If it already knows about it's controllers, why even have to put the app.resource() in at all?

Why not just define app.controllers.first, app.controllers.second, et al and have them automagically become resources?

Anyone have a strong argument for a preference?

I don't have a strong argument, but I prefer //A (non-functional) as this is easier, from my experience, to wrap my primitive brain around : )

In any case, I'll be uber-excited to get my hands on this addition!

from base12.

hunterloftis avatar hunterloftis commented on June 27, 2024
// A
  app.resource('first', middleware1, middleware2, function() {
    this.resource('second', function() {
      this.resource('third', function() {
        this.get('innersub');
      );
    });
    this.resource('ii');
    this.all('sub1');
    this.post('subtwo', 'sub2');
  });

@katowulf, I agree that A seems more natural - so @dbecher suggested this to keep what I like from B (the levels). Should be merged in just a day or two!

from base12.

snodgrass23 avatar snodgrass23 commented on June 27, 2024

express has been updated which includes resourceful routing

from base12.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.