├── .gitignore
├── .nodemonignore
├── Gruntfile.js
├── LICENSE
├── README.md
├── app
├── app.js
├── collections
│ ├── base.js
│ ├── repos.js
│ └── users.js
├── controllers
│ ├── home_controller.js
│ ├── repos_controller.js
│ └── users_controller.js
├── lib
│ └── handlebarsHelpers.js
├── models
│ ├── base.js
│ ├── build.js
│ ├── repo.js
│ └── user.js
├── router.js
├── routes.js
├── templates
│ ├── __layout.hbs
│ ├── home
│ │ └── index.hbs
│ ├── repos
│ │ ├── index.hbs
│ │ └── show.hbs
│ ├── user_repos_view.hbs
│ └── users
│ │ ├── index.hbs
│ │ ├── show.hbs
│ │ └── show_lazy.hbs
└── views
│ ├── app_view.js
│ ├── base.js
│ ├── home
│ └── index.js
│ ├── repos
│ ├── index.js
│ └── show.js
│ ├── user_repos_view.js
│ └── users
│ ├── index.js
│ └── show.js
├── assets
├── stylesheets
│ ├── base_view.styl
│ ├── index.styl
│ └── vendor
│ │ └── bootstrap.min.css
└── vendor
│ ├── es5-sham.js
│ ├── es5-shim.js
│ ├── jquery-1.9.1.min.js
│ └── json2.js
├── config
├── default.yml
├── development.yml
└── production.yml
├── index.js
├── package.json
├── public
├── favicon.ico
└── images
│ └── .gitkeep
├── server
└── lib
│ └── data_adapter.js
└── test
└── app
├── collections
└── repos.test.js
├── models
└── user.test.js
└── views
└── users_show_view.test.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | public/mergedAssets.js
3 | app/templates/compiledTemplates.js
4 | public/styles.css
5 | .DS_Store
6 | npm-debug.log
7 | config/runtime.json
8 | *.swp
9 | *.swo
10 |
--------------------------------------------------------------------------------
/.nodemonignore:
--------------------------------------------------------------------------------
1 | /public/*
2 | /assets/*
3 | /**/compiledTemplates.js
4 | /node_modules/*
5 | *.swp
6 | *.swo
7 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 |
3 | var stylesheetsDir = 'assets/stylesheets';
4 | var rendrDir = 'node_modules/rendr';
5 | var rendrHandlebarsDir = 'node_modules/rendr-handlebars';
6 | var rendrModulesDir = rendrDir + '/node_modules';
7 |
8 | module.exports = function(grunt) {
9 | // Project configuration.
10 | grunt.initConfig({
11 | pkg: grunt.file.readJSON('package.json'),
12 |
13 | stylus: {
14 | compile: {
15 | options: {
16 | paths: [stylesheetsDir],
17 | 'include css': true
18 | },
19 | files: {
20 | 'public/styles.css': stylesheetsDir + '/index.styl'
21 | }
22 | }
23 | },
24 |
25 | handlebars: {
26 | compile: {
27 | options: {
28 | namespace: false,
29 | commonjs: true,
30 | processName: function(filename) {
31 | return filename.replace('app/templates/', '').replace('.hbs', '');
32 | }
33 | },
34 | src: "app/templates/**/*.hbs",
35 | dest: "app/templates/compiledTemplates.js",
36 | filter: function(filepath) {
37 | var filename = path.basename(filepath);
38 | // Exclude files that begin with '__' from being sent to the client,
39 | // i.e. __layout.hbs.
40 | return filename.slice(0, 2) !== '__';
41 | }
42 | }
43 | },
44 |
45 | watch: {
46 | scripts: {
47 | files: 'app/**/*.js',
48 | tasks: ['rendr_stitch'],
49 | options: {
50 | interrupt: true
51 | }
52 | },
53 | templates: {
54 | files: 'app/**/*.hbs',
55 | tasks: ['handlebars'],
56 | options: {
57 | interrupt: true
58 | }
59 | },
60 | stylesheets: {
61 | files: [stylesheetsDir + '/**/*.styl', stylesheetsDir + '/**/*.css'],
62 | tasks: ['stylus'],
63 | options: {
64 | interrupt: true
65 | }
66 | }
67 | },
68 |
69 | rendr_stitch: {
70 | compile: {
71 | options: {
72 | dependencies: [
73 | 'assets/vendor/**/*.js'
74 | ],
75 | npmDependencies: {
76 | underscore: '../rendr/node_modules/underscore/underscore.js',
77 | backbone: '../rendr/node_modules/backbone/backbone.js',
78 | handlebars: '../rendr-handlebars/node_modules/handlebars/dist/handlebars.runtime.js',
79 | async: '../rendr/node_modules/async/lib/async.js'
80 | },
81 | aliases: [
82 | {from: rendrDir + '/client', to: 'rendr/client'},
83 | {from: rendrDir + '/shared', to: 'rendr/shared'},
84 | {from: rendrHandlebarsDir, to: 'rendr-handlebars'},
85 | {from: rendrHandlebarsDir + '/shared', to: 'rendr-handlebars/shared'}
86 | ]
87 | },
88 | files: [{
89 | dest: 'public/mergedAssets.js',
90 | src: [
91 | 'app/**/*.js',
92 | rendrDir + '/client/**/*.js',
93 | rendrDir + '/shared/**/*.js',
94 | rendrHandlebarsDir + '/index.js',
95 | rendrHandlebarsDir + '/shared/*.js'
96 | ]
97 | }]
98 | }
99 | }
100 | });
101 |
102 | grunt.loadNpmTasks('grunt-contrib-stylus');
103 | grunt.loadNpmTasks('grunt-contrib-watch');
104 | grunt.loadNpmTasks('grunt-contrib-handlebars');
105 | grunt.loadNpmTasks('grunt-rendr-stitch');
106 |
107 | grunt.registerTask('runNode', function () {
108 | grunt.util.spawn({
109 | cmd: 'node',
110 | args: ['./node_modules/nodemon/nodemon.js', '--debug', 'index.js'],
111 | opts: {
112 | stdio: 'inherit'
113 | }
114 | }, function () {
115 | grunt.fail.fatal(new Error("nodemon quit"));
116 | });
117 | });
118 |
119 |
120 | grunt.registerTask('compile', ['handlebars', 'rendr_stitch', 'stylus']);
121 |
122 | // Run the server and watch for file changes
123 | grunt.registerTask('server', ['runNode', 'compile', 'watch']);
124 |
125 | // Default task(s).
126 | grunt.registerTask('default', ['compile']);
127 | };
128 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Airbnb
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Note:
2 |
3 | ## This repo has been deprecated in favor of the
4 | [rendr-examples](https://github.com/rendrjs/rendr-examples) repo, which is
5 | easier to keep up-to-date.
6 |
7 |
8 | -----------
9 |
10 | # Rendr App Template
11 | ## GitHub Browser
12 |
13 | The purpose of this little app is to demonstrate one way of using Rendr to build a web app that runs on both the client and the server.
14 |
15 | 
16 |
17 | ## Running the example
18 |
19 | First, make sure to have Node >= 0.8.0 [installed on your system](http://nodejs.org/). Also, make sure to have `grunt-cli` installed globally.
20 |
21 | $ npm install -g grunt-cli
22 |
23 | If you see an error on startup that looks [like this](https://github.com/airbnb/rendr-app-template/issues/2), then you may need to un-install a global copy of `grunt`:
24 |
25 | $ npm uninstall -g grunt
26 |
27 | Clone this repo to a local directory and run `npm install` to install dependencies:
28 |
29 | $ git clone git@github.com:airbnb/rendr-app-template.git
30 | $ cd rendr-app-template
31 | $ npm install
32 |
33 | Then, use `grunt server` to start up the web server. Grunt will recompile and restart the server when files change.
34 |
35 | $ grunt server
36 | Running "bgShell:runNode" (bgShell) task
37 |
38 | Running "handlebars:compile" (handlebars) task
39 | File "app/templates/compiledTemplates.js" created.
40 |
41 | Running "rendr_stitch:compile" (rendr_stitch) task
42 | 4 Apr 09:58:02 - [nodemon] v0.7.2
43 | 4 Apr 09:58:02 - [nodemon] watching: /Users/spike1/code/rendr-app-template
44 | 4 Apr 09:58:02 - [nodemon] starting `node index.js`
45 | 4 Apr 09:58:02 - [nodemon] reading ignore list
46 | File "public/mergedAssets.js" created.
47 |
48 | Running "stylus:compile" (stylus) task
49 | File public/styles.css created.
50 | server pid 87338 listening on port 3030 in development mode
51 |
52 | Running "watch" task
53 | Waiting...
54 |
55 | Now, pull up the app in your web browser. It defaults to port `3030`.
56 |
57 | $ open http://localhost:3030
58 |
59 | You can choose a different port by passing the `PORT` environment variable:
60 |
61 | $ PORT=80 grunt server
62 |
63 | ### GitHub API rate limit
64 |
65 | GitHub [rate limits](http://developer.github.com/v3/#rate-limiting) unauthenticated requests to its public API to 60 requests per hour per IP. This should be enough for just playing with the sample app, but if you pull it down and start developing off it you may run up against the rate limit.
66 |
67 | If this happens to you, you can supply your GitHub creds for HTTP Basic Auth using the BASIC_AUTH environment variable. **Be very, very careful with this!** It means you will be typing your GitHub credentials in plain text, which will be saved to your Bash history and may be intercepted by other programs. If you do this, immediately change your password before and afterwards. This should only be necessary if you're developing on the app and need to keep refreshing the page.
68 |
69 | $ BASIC_AUTH=githubusername:githubpassword grunt server
70 |
71 | **You've been warned.** Your best bet may be to alter the project to read from your favorite RESTful API.
72 |
73 | ## Getting Started With Rendr
74 |
75 | It's worthwhile to read the first [blog post](http://nerds.airbnb.com/weve-launched-our-first-nodejs-app-to-product), which has some background on Rendr and its *raison d'être*.
76 |
77 | This basic Rendr app looks like a hybrid between a standard client-side MVC Backbone.js app and an Express app, with a little Rails convention thrown in.
78 |
79 | Check out the directory structure:
80 |
81 | |- app/
82 | |--- collections/
83 | |--- controllers/
84 | |--- models/
85 | |--- templates/
86 | |--- views/
87 | |--- app.js
88 | |--- router.js
89 | |--- routes.js
90 | |- assets/
91 | |- config/
92 | |- public/
93 | |- server/
94 |
95 | **Note**: I want to stress that this is just one way to build an app using Rendr. I hope it can evolve to support a number of different app configurations, with the shared premise that the components should be able to run on either side of the wire. For example, the full-on client-side MVC model isn't appropriate for all types of apps. Sometimes it's more appropriate to load HTML fragments over the wire, also known as PJAX. Rendr apps should be able to support this as well.
96 |
97 | ## CommonJS using Stitch
98 |
99 | Node.js uses the CommonJS module pattern, and using a tool called [Stitch](https://github.com/sstephenson/stitch), we can emulate it in the browser. This looks familiar in Node.js:
100 |
101 | ```js
102 | var User = require('app/models/user');
103 | ```
104 | Using Stitch, we can use the same `require()` function in the browser. This allows us to focus on application logic, not packaging modules separately for client and server.
105 |
106 | In Node.js, you can also use `require()` to load submodules within NPM models. For example, we could load Rendr's base view in order to extend it to create a view for our app.
107 |
108 | ```js
109 | var BaseView = require('rendr/shared/base/view');
110 | ```
111 |
112 | Because of a trick in the way we do Stitch packaging, this module path works in the browser as well.
113 |
114 | ## Routes file
115 |
116 | ```js
117 | // app/routes.js
118 | module.exports = function(match) {
119 | match('', 'home#index');
120 | match('repos', 'repos#index');
121 | match('repos/:owner/:name', 'repos#show');
122 | match('users' , 'users#index');
123 | match('users/:login', 'users#show');
124 | };
125 |
126 | ```
127 |
128 | ## Controllers
129 |
130 | A controller is a simple JavaScript object, where each property is a controller action. Keep in mind that controllers are executed on both the client and the server. Thus, they are an abstraction whose sole responsibility is to specify which data is needed to render the view, and which view to render.
131 |
132 | On the server, controllers are executed in response to a request to the Express server, and are used to render the initial page of HTML. On the client, controllers are executed in response to `pushState` events as the user navigates the app.
133 |
134 | Here is a very simple controller:
135 |
136 | ```js
137 | // app/controllers/home_controller.js
138 | module.exports = {
139 | index: function(params, callback) {
140 | callback(null, 'home_index_view');
141 | }
142 | };
143 |
144 | ```
145 |
146 | Every action gets called with two arguments: `params` and `callback`. The `params` object contains both route params and query string params. `callback` is called to kick off view rendering. It has this signature:
147 |
148 | ```js
149 | function(err, viewName, viewData) {}
150 | ```
151 |
152 | ### `err`
153 | Following the Node.js convention, the first argument to the callback is `err`. We'll pass null here because we're not fetching any data, but if we were, that's how we'd communicate a fetching error.
154 |
155 | ### `viewName`
156 | This is a string identifier of a view, used by the router to find the view class, i.e.:
157 |
158 | ```js
159 | require('app/views/' + viewName);
160 | ```
161 |
162 | ### `viewData` (optional)
163 | An object to pass to the view constructor. This is how we pass data to the view.
164 |
165 | All our `index` action above really does is specify a view class. This is the simple case -- no data fetching, just synchronous view rendering.
166 |
167 | It gets more interesting when we decide to fetch some data. Check out the `repos_controller` below:
168 |
169 | ```js
170 | // app/controllers/repos_controller.js
171 | module.exports = {
172 | // ...
173 |
174 | show: function(params, callback) {
175 | var spec = {
176 | model: {model: 'Repo', params: params}
177 | };
178 | this.app.fetch(spec, function(err, result) {
179 | callback(err, 'repos_show_view', result);
180 | });
181 | }
182 | };
183 |
184 | ```
185 |
186 | You see here that we call `this.app.fetch()` to fetch our Repo model. Our controller actions are executed in the context of the router, so we have a few properties and methods available, one of which is `this.app`. This is the instance of our application's App context, which is a sublcass of `rendr/base/app`, which itself is a subclass of `Backbone.Model`. You'll see that we inject `app` into every model, view, collection, and controller; this is how we maintain app context throughout our app.
187 |
188 | You see here that we call `callback` with the `err` that comes from `this.app.fetch()`, the view class name, and the `result` of the fetch. `result` in this case is an object with a single `model` property, which is our instance of the `Repo` model.
189 |
190 | `this.app.fetch()` does a few nice things for us; it fetches models or collections in parallel, handles errors, does caching, and most importantly, provides a way to boostrap the data fetched on the server in a way that is accessible by the client-side on first render.
191 |
192 | ## Views
193 |
194 | A Rendr view is a subclass of `Backbone.View` with some additional methods added to support client-server rendering, plus methods that make it easier to manage the view lifecycle.
195 |
196 | Creating your own view should look familiar if you've used Backbone:
197 |
198 | ```js
199 | // app/views/home_index_view.js
200 | var BaseView = require('./base_view');
201 |
202 | module.exports = BaseView.extend({
203 | className: 'home_index_view',
204 |
205 | events: {
206 | 'click p': 'handleClick',
207 | },
208 |
209 | handleClick: function() {…}
210 | });
211 | module.exports.id = 'HomeIndexView';
212 | ```
213 |
214 | You can add `className`, `tagName`, `events`, and all of the other `Backbone.View` properties you know and love.
215 |
216 | We set the property `id` on the view constructor to aid in the view hydration process. More on that later.
217 |
218 | Our views, just like all of the code in the `app/` directory, are executed in both the client and the server, but of course certain behaviors are only relevant in the client. The `events` hash is ignored by the server, as well as any DOM-related event handlers.
219 |
220 | Notice there's no `render()` method or `template` property specified in the view. The philosophy here is that sensible defaults and convention over configuration should allow you to skip all the typical boilerplate when creating views. The `render()` method should be the same for all your views; all it does is mash up the template with some data to generate HTML, and insert that HTML into the DOM element.
221 |
222 | Now, because we're not using a DOM to render our views, we must make sure that the view returns all its HTML as a string. On the server, `view.getHtml()` is called, which returns the view's outer HTML, including wrapper element. This is then handed to Express, which wraps the page with a layout and sends the full HTML page to the client. Behind the scenes, `view.getHtml()` calls `view.getInnerHtml()` for the inner HTML of the view, not including wrapping element, and then constructs the wrapping element based on the `tagName`, `className`, etc. properties, and the key-value pairs of HTML attributes returned by `view.getAttributes()`, which allows you to pass custom attributes to the outer element.
223 |
224 | On the client, `view.render()` is called, which updates the view's DOM element with the HTML returned from `view.getInnerHtml()`. By default, Backbone will create the wrapper DOM element on its own. We make sure to also set any custom HTML attributes in `view.getAttributes()` on the element.
225 |
226 | ### The view lifecycle
227 |
228 |
229 | A common need is to run some initialization code that touches the DOM after render, for things like jQuery sliders, special event handling, etc. Rather than overriding the `render()` method, use `postRender()`. The `postRender()` method is executed for every view once after rending, including after initial pageload.
230 |
231 | ```js
232 | // app/views/home_index_view.js
233 | var BaseView = require('./base_view');
234 |
235 | module.exports = BaseView.extend({
236 | className: 'home_index_view',
237 |
238 | postRender: function() {
239 | this.$('.slider').slider();
240 | }
241 | });
242 | module.exports.id = 'HomeIndexView';
243 | ```
244 |
245 | If you have a need to customize the way your views generate HTML, there are a few specific methods you can override.
246 |
247 | #### getTemplateName()
248 |
249 | By default, `getTemplateName()` returns the underscored version of the view constructor's `id` property; so in our case, `home_index_view`. It will also look for `options.template_name`, which is useful for initialing views to use a certain template. The view will look in `app/templates` for the value returned by this function.
250 |
251 | #### getTemplate()
252 |
253 | If `getTemplateName()` isn't enough, you can override `getTemplate()` to return a function that takes a single `data` argument and returns HTML:
254 |
255 | ```js
256 | function(data) {
257 | ...
258 | return html;
259 | }
260 | ```
261 |
262 | This HTML is used to populate the view's inner HTML; that is, not including the wrapper element, which you can specify on the view itself using `tagName`, `className`, and `id`.
263 |
264 | #### getInnerHtml()
265 |
266 | If you're building some sort of composite view that doesn't utilize a simple template, override `getInnerHtml()`. This is useful for tabbed views, collection views, etc.
267 |
268 | #### getHtml()
269 |
270 | You probably shouldn't ever need to override this; by default it just combines the HTML returned by `getInnerHtml()` and the HTML attributes returned by `getAttributes()` to produce an outer HTML string.
271 |
272 | ## The view hierarchy
273 |
274 | Rendr provides a Handlebars helper `{{view}}` that allows you to declaratively nest your views, creating a view hierarchy that you can traverse in your JavaScript. Check out [`app/templates/users/show.hbs`](https://github.com/airbnb/rendr-app-template/blob/master/app/templates/users/show.hbs) and [`app/views/users/show.js`](https://github.com/airbnb/rendr-app-template/blob/master/app/views/users/show.js) for an example:
275 |
276 | ```html
277 |
278 | ...
279 |
280 |
287 | ```
288 |
289 | You see that we use the `{{view}}` helper with an argument that indicates which view to be rendered. We can pass data into the view using [Handlebars' hash arguments](http://handlebarsjs.com/expressions.html). Anything you pass as hash arguments will be pass to the subview's constructor and be accessible as `this.options` within the subview. There are a few special options you can pass to a view: `model` or `collection` can be used to directly pass a model or collection instance to a subview. The options `model_name` + `model_id` or `collection_name` + `collection_params` can be used in conjunction with `lazy="true"` to lazily fetch models or collections; more on that later.
290 |
291 | Now, from within the `users/show` view, we can access any child views using the `this.childViews` array. A good way to debug and get a feel for this in the browser is to drill down into the global `App` property, which is your instance of `BaseApp`. From `App` you can access other parts of your application. `App.router` is your instance of `ClientRouter`, and it has a number of properties that you can inspect. One of these is `App.router.currentView`, which will always point to the current main view for a page. For example, if you are viewing wycats' page in our app, [http://localhost:3030/users/wycats](http://localhost:3030/users/wycats), `currentView` will be an instance of `users/show`:
292 |
293 | App.router.currentView
294 | => child {render: function, cid: "view434", model: child, options: Object, $el: p.fn.p.init[1]…}
295 |
296 | From there, we can find our child `user_repos_view` view:
297 |
298 | App.router.currentView.childViews
299 | => [child]
300 |
301 | App.router.currentView.childViews[0]
302 | => child {render: function, cid: "view436", options: Object, $el: p.fn.p.init[1], el: div.user_repos_view…}
303 |
304 | Check out its collection property, which is the instance of `Repos` which we fetched in the controller and passed down in the `{{view}}` helper:
305 |
306 | App.router.currentView.childViews[0].collection
307 | => child {options: Object, app: child, params: Object, meta: Object, length: 30…}
308 |
309 | You can nest subviews *ad infinitum*. Our `user_repos_view` has an empty `childViews` array now, but we could add some subviews if we found it useful for organizing our codebase, or keeping things DRY.
310 |
311 | App.router.currentView.childViews[0].childViews
312 | => []
313 |
314 | Views also have a `parentView` property, which will be non-null unless they are a top-level view.
315 |
316 | App.router.currentView.childViews[0].parentView === App.router.currentView
317 | => true
318 |
319 | App.router.currentView.parentView
320 | => null
321 |
322 | ## Lazy-loading data for views
323 |
324 | So far, our [`users#show` action](https://github.com/airbnb/rendr-app-template/blob/master/app/controllers/users_controller.js#L11) pulls down both a `User` model and a `Repos` collection for that model. If we were to navigate from `users#index` to `users#show`, we already have that user model cached in memory (because we fetched it in order to render the list), but we have to make a roundtrip to the server to fetch the `Repos`, which aren't part of the `User` attributes. This means that instead of immediately rendering the `users/show` view, we wait for the `Repos` API call to finish. But what if instead we want to lazy-load the `Repos` so we can render that view immediately for a better user experience?
325 |
326 | We can achieve this by lazy-loading models or collections in our subviews. Check out the `users#show_lazy` action, which demonstrates this approach:
327 |
328 | ```js
329 | // app/controllers/users_controller.js
330 | module.exports = {
331 | // ...
332 |
333 | show_lazy: function(params, callback) {
334 | var spec = {
335 | model: {model: 'User', params: params}
336 | };
337 | this.app.fetch(spec, function(err, result) {
338 | if (err) return callback(err);
339 | // Extend the hash of options we pass to the view's constructor
340 | // to include the `template_name` option, which will be used
341 | // to look up the template file. This is a convenience so we
342 | // don't have to create a separate view class.
343 | _.extend(result, {
344 | template_name: 'users/show_lazy'
345 | });
346 | callback(err, 'users/show', result);
347 | });
348 | }
349 | }
350 | ```
351 | The first thing to notice is that in our fetch `spec`, we only specify the `User` model, leaving out the `Repos` collection. Then, we tell the view to use a different template than the default. We do this by passing in a `template_name` property to the view's options, which is passed to its constructor. We extend the `result` object to have this; the third argument to our `callback` is an object that's passed to the view's constructor. We could have also created a separate view class in JavaScript for this, to match our new template.
352 |
353 | Here's the `users/show_lazy` template, abbreviated:
354 |
355 | ```html
356 |
357 | ...
358 |
359 |