YahooArchive / mojito

[archiving soon] Yahoo! Mojito Framework
BSD 3-Clause "New" or "Revised" License
1.57k stars 214 forks source link

provide a way for middleware to populate page data #1244

Open drewfish opened 11 years ago

drewfish commented 11 years ago

Our current "page" data object is unique to each request, and is a great place to store request-specific objects/data. However, there's no way for middleware to put objects/data into it.

caridy commented 11 years ago

Since the page obj is probably going to have contextualized stuff (don't know), I will suggest to allow requests to attach a page object into the request object (or potentially req.locals, which is the standard way of doing it in express 3) and then getting mojito.js to augment that object with more stuff if it exists, or just create a new object.

drewfish commented 11 years ago

Well the middleware is actually just as request-specific as the page object (including contextualization).

I'm looking at line 33 of lib/output-handler.server.js, which is where the page object is created. Right after creating it we could also merge in req.page (or req.locals or whatever we want to call it).

drewfish commented 11 years ago

Oh hmm... I see what you mean, mojito.js is pushing data into the page object. That's a little dirty and is being done that way because the output handler doesn't have direct access to the store. However, the output handler does have direct access to the request object, so I argue that the output handler ctor should be responsible (instead of mojito.js) for moving data from req.page[1] to the page object.

[1] ... or whatever we call it