Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Goldhofer committed Oct 24, 2017
2 parents 6642a17 + a5147cf commit cc5df78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function logTime(message, startTime, endTime) {


function mithrilRenderLoader(view) {
// prevents some(!) messed up states - the loader is currently fast enough enough
this.cacheable(false);

const timeStart = Date.now();
// the render-mithril operation is async
var done = this.async();
Expand All @@ -21,6 +24,15 @@ function mithrilRenderLoader(view) {
"export": false // use module.exports or return result as string (html-loader)
}, this.query);

if (o.model === null) {
this.emitWarning("property 'model' is not for mithril-render");
o.model = {};
}

// pass a uid to mithril component
o.model.ID = `${this.resourcePath}${Date.now()}${Math.random()}`;
o.model.COMPONENT_ID = this.resourcePath;

// prototype - webpack require
const requests = [];
const self = this;
Expand Down Expand Up @@ -53,7 +65,7 @@ function mithrilRenderLoader(view) {
render(m(view, o.model))
.then((html) => {
timeResolve = Date.now();
o.profile && logTime(`render ${this.resource}`, timeStart, timeResolve);
o.profile && logTime(`render component ${this.resource}`, timeStart, timeResolve);
global.resolve = undefined;

const dependencies = [];
Expand All @@ -71,13 +83,15 @@ function mithrilRenderLoader(view) {
delete require.cache[filepath];
});

// tryout
this.addDependency(this.resourcePath);

return html;
})
.then((html) => Promise
.all(requests)
.then((results) => {
o.profile && logTime(`resolve ${this.resource}`, timeResolve, Date.now());
o.profile && logTime(`resolve webpack requires ${this.resource}`, timeResolve, Date.now());

results.forEach((data) => {
html = html.replace(data.id, data.source);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mithril-render-loader",
"version": "0.4.0",
"version": "0.5.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cc5df78

Please sign in to comment.