Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Created January 21, 2014 06:21
Show Gist options
  • Save shadowmint/8535233 to your computer and use it in GitHub Desktop.
Save shadowmint/8535233 to your computer and use it in GitHub Desktop.
Example of deferred~
/* Load page navigation */
public loadNav():void {
var nav = new bs.widgets.Nav(this._$nav.find(PageLayout.NAV_ACCORDION));
nav.register('bedroom-layout', () => {
console.log(this);
this._loadPage('room_selector_nav.html', 'room_selector_page.html').then(() => {
bs.app.room.loadRoom();
});
});
nav.register('bedroom-doors', () => {
this._loadPage('add_doors_nav.html', 'add_doors_page.html')
});
nav.register('bedroom-bed', () => {
this._loadPage('choose_bed_nav.html', 'choose_bed_page.html')
});
nav.register('bedroom-furniture', () => {
this._loadPage('choose_furniture_nav.html', 'choose_furniture_page.html')
});
nav.register('bedroom-price', () => {
this._loadPage('get_price_nav.html', 'get_price_page.html')
});
nav.load(0);
this._nav = nav;
}
/* Load a handlebars nav and page template into the page */
private _loadPage(nav_template:string, page_template:string) {
var def = new $.Deferred();
$.when(
this._getTemplate(nav_template, (template:any) => {
var content = template(bs.app.state);
this._nav.setContent(content);
}),
this._getTemplate(page_template, (template:any) => {
var content = template(bs.app.state);
this._$content.html(content);
})
).done(() => def.resolve());
return def;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment