Skip to content

Commit 4fd471c

Browse files
Make possible to pass renderer promise
1 parent 446d444 commit 4fd471c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/core.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ export default class Core extends Emitter {
3535
this.cache.set(this.location.pathname, this.properties);
3636

3737
// Get the page renderer and properly setup it.
38-
this.From = new this.properties.renderer(this.properties);
39-
this.From.setup();
38+
this.properties.renderer
39+
.then(Renderer => {
40+
this.From = new Renderer(this.properties);
41+
this.From.setup();
42+
});
4043

4144
// Events variables.
4245
this._navigate = this.navigate.bind(this);
@@ -216,7 +219,9 @@ export default class Core extends Emitter {
216219
async afterFetch() {
217220
// We are calling the renderer attached to the view we just fetched and we
218221
// are adding the [data-router-view] in our DOM.
219-
this.To = new this.properties.renderer(this.properties);
222+
const Renderer = await this.properties.renderer;
223+
224+
this.To = new Renderer(this.properties);
220225
this.To.add();
221226

222227
// We then emit a now event right before the view is shown to create a hook

src/helpers.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,16 @@ export default class Helpers {
127127
* @static
128128
*/
129129
getRenderer(slug) {
130-
return slug in this.renderers ? this.renderers[slug] : Renderer;
130+
if (slug in this.renderers) {
131+
if (typeof this.renderers[slug].then === 'function') {
132+
return Promise.resolve(this.renderers[slug])
133+
.then(({default: cons}) => cons);
134+
}
135+
136+
return Promise.resolve(this.renderers[slug]);
137+
}
138+
139+
return Promise.resolve(Renderer);
131140
}
132141

133142
/**

0 commit comments

Comments
 (0)