This file contains 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
// request to "/" | |
<body> | |
<div id="app-placeholder"> | |
<header>Index Page</header> | |
<article> | |
Some Content | |
</article> | |
</div> | |
<script> | |
window.bootstrap = { |
This file contains 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
module.exports = function ( sandbox ) { | |
var Hotel = sandbox.mvc.Model.extend( { urlRoot : "/hotels" } ); | |
return sandbox.mvc.App.extend( { | |
$el: sandbox.context.element, | |
constructor: function () { | |
this.hotel = new Hotel(); |
This file contains 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
import {Inject} from 'di/annotations'; | |
import Http from 'http'; | |
import Dom from 'dom'; | |
@Inject(Http) | |
export class Gallery { | |
constructor (http: Http) { | |
this.http = http; | |
} | |
run ({$el: Dom}) { |
This file contains 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
// request to "/" | |
<body> | |
<div id="app-placeholder"> | |
<header>Index Page</header> | |
<article> | |
Some Content | |
</article> | |
</div> | |
<script src="app.js"></script> | |
</body> |
This file contains 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
// returned on request to any route | |
<body> | |
<div id="app-placeholder"></div> | |
<script src="app.js"></script> | |
</body> |
This file contains 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
var dom = require('jQuery'); | |
var http = { get: dom.get }; | |
var Gallery = require('gallery'); | |
client.get('/', function () { | |
var scope = { | |
isServer: false, | |
$el: dom('#gallery-placeholder') | |
}; | |
Gallery[Gallery.length - 1](http, scope); |
This file contains 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
module.exports = ['http', 'scope', function Gallery (http, scope) { | |
// ... | |
// shared | |
function loadMore () { | |
return http.get('/products?page=' + page++ + '&limit=10', function(products) { | |
products.reduce(function($ul, product){ | |
return $ul.append('<li>' + product.title + '</li>'); | |
}, $gallery.find('.products')) | |
}); |
This file contains 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
module.exports = ['http', 'scope', function Gallery (http, scope) { | |
var page = scope.isServer ? 1 : 2; | |
var $gallery = scope.$el; | |
if (scope.isServer) | |
$gallery.append( | |
'<ul class="products"></ul>' + | |
'<button class="more">more</button>' | |
); | |
// ... |
This file contains 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
module.exports = ['dom', 'http', 'scope', function Gallery (dom, http, scope) { | |
// ... | |
if (!scope.isServer) { // client-side | |
$gallery.find('.more').on('click', loadMore); | |
} else { // server-side | |
loadMore(); | |
} | |
}]; |
This file contains 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
CSSSelect('.products', $ul); | |
{ | |
"type": "tag", | |
"name": "ul", | |
"attribs": { class: 'products' }, | |
"children": [], | |
"next": null, | |
"prev": null, | |
"parent": null |
NewerOlder