Last active
August 29, 2015 14:11
-
-
Save commuterjoy/a1fd0d3319548c0b25b9 to your computer and use it in GitHub Desktop.
Stream model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// returns a rendered list of items | |
res.get(req, res, next) { | |
/** | |
* A stream object accepts an array of content id UUIDs or CAPI search strings | |
* and returns a blob of HTML representing the stream. | |
* | |
* The returned HTML is a sequence of article card components. | |
*/ | |
var content = Promise.all( | |
ft.get(['d3fe0b06-9e43-11e3-b429-00144feab7de', ...], | |
fastft.get('regions:london'), | |
market.get('lse:twt') | |
... | |
).then(function (items) { | |
new Stream({ | |
api: [..., ...], | |
fastft: [..., ...], | |
market: [..., ...], | |
userprefs: [..., ...] | |
}) | |
.sortByDate // Orders the items by date descending | |
.sortByVisualTone // Groups the items by their tone, Eg. news, analysis, comment etc. | |
.applyTextures // Annotate the items with texture, Eg. highlight some items | |
.withFastFT(true) // Interleave the fastFT data | |
.showRelatedTopics(5) // Show n related topics at the foot of the stream | |
.requestingUser({ id: req.params.uid }) // Metadata about the person who requested the stream | |
.isFollowable(true) // Can someone follow this stream? | |
.isUserStream(true) // Not sure we need this distinction? | |
.title('Save for later') // Display title | |
.id('forlaters') // DOM id (?) | |
.page(1) // Pagination, Eg. '1 of n' | |
.applyFilters() // API v1 filter configation. Eg, { regions: ['London', 'New York'] } | |
.notFound(message) // Message to display upon the stream being empty, Eg. 'Sorry. No articles found' | |
.render // Respond with a blob of HTML representing the stream. | |
}) | |
} |
Arjun and I spoke about this quite a bit.
- We think the controllers should still be in charge of fetching the data and passing it to the stream.
- The Stream model is really a view model the returns an object.
- The stream model can be passed to the res.render to be converted to HTML
The main objectives are to a) centralise the messy splay of streams logic and to begin to unit test it, b) keep all this logic out of any individual controller.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@wheresrhys Yes, sorting by date is just one option - you can imagine, sortByNumberOfComments or groupByTone, though some of this is probably better dictated by the server etc.
Yeah, a few editorial folk are quite in to the idea of using the next site to help curate lists.