Comments (7)
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.
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.
Would love to make it easy to do something like this:
http://weblog.jamisbuck.org/2007/2/5/nesting-resources
from base12.
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.
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.
// 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.
express has been updated which includes resourceful routing
from base12.
Related Issues (20)
- Cycle Not Quite Working HOT 2
- git: don't ignore case! HOT 1
- Cannot run with debug HOT 1
- npm install failing HOT 1
- nimbus.json error HOT 5
- License isn't posted HOT 2
- default configs should update to match project name instead of default 'base12'
- Add reset password functionality to user component
- pull render methods from components and move to global location
- Remove bloated dependencies HOT 1
- load config from env vars when needed
- register error throws text of [Object object]
- add default mailer component
- move mongoose libs to separate node module HOT 2
- base12 or make command for copying remote config to heroku
- grunt build scripts
- look into usefulness of using yeoman generators
- Make each component's public folder content accessible HOT 3
- Update for Node 4.0 and clear out now irrelevant issues.
- Need a subdomain example for Heroku
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from base12.