Skip to content

Commit 1b03461

Browse files
authored
Merge pull request #20 from vegarringdal/new_loader
fix(hmr-css), needs fusebox 1.3.123-preview.11 ++
2 parents e35c030 + b11424b commit 1b03461

File tree

3 files changed

+47
-73
lines changed

3 files changed

+47
-73
lines changed

dist/commonjs/fuse-box-aurelia-hmr-plugin.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export declare class FuseBoxAureliaHmrPlugin {
33
private context;
44
private reloadPageOnly;
55
private timer;
6+
private loader;
67
constructor(loader: FuseBoxAureliaLoader, reloadPageOnly: boolean);
7-
hmrUpdate(data: any): Promise<boolean>;
8+
hmrUpdate(data: any): boolean;
89
}

dist/commonjs/fuse-box-aurelia-hmr-plugin.js

Lines changed: 32 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,46 @@
1-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2-
return new (P || (P = Promise))(function (resolve, reject) {
3-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6-
step((generator = generator.apply(thisArg, _arguments || [])).next());
7-
});
8-
};
9-
var __generator = (this && this.__generator) || function (thisArg, body) {
10-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t;
11-
return { next: verb(0), "throw": verb(1), "return": verb(2) };
12-
function verb(n) { return function (v) { return step([n, v]); }; }
13-
function step(op) {
14-
if (f) throw new TypeError("Generator is already executing.");
15-
while (_) try {
16-
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
17-
if (y = 0, t) op = [0, t.value];
18-
switch (op[0]) {
19-
case 0: case 1: t = op; break;
20-
case 4: _.label++; return { value: op[1], done: false };
21-
case 5: _.label++; y = op[1]; op = [0]; continue;
22-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
23-
default:
24-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
25-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
27-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
28-
if (t[2]) _.ops.pop();
29-
_.trys.pop(); continue;
30-
}
31-
op = body.call(thisArg, _);
32-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
33-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
34-
}
35-
};
361
Object.defineProperty(exports, "__esModule", { value: true });
372
var FuseBoxAureliaHmrPlugin = (function () {
383
function FuseBoxAureliaHmrPlugin(loader, reloadPageOnly) {
394
if (!reloadPageOnly) {
405
var HmrContext = require('aurelia-hot-module-reload').HmrContext;
416
this.context = new HmrContext(loader);
7+
this.loader = loader;
428
}
439
this.reloadPageOnly = reloadPageOnly;
4410
}
4511
FuseBoxAureliaHmrPlugin.prototype.hmrUpdate = function (data) {
46-
return __awaiter(this, void 0, void 0, function () {
47-
var moduleId;
48-
return __generator(this, function (_a) {
49-
switch (_a.label) {
50-
case 0:
51-
if (!this.reloadPageOnly) return [3 /*break*/, 1];
52-
clearTimeout(this.timer);
53-
this.timer = setTimeout(function () {
54-
document.location.reload();
55-
}, 250);
56-
return [3 /*break*/, 5];
57-
case 1:
58-
if (!(data.type === 'js')) return [3 /*break*/, 5];
59-
FuseBox.flush();
60-
FuseBox.dynamic(data.path, data.content);
61-
if (FuseBox.mainFile) {
62-
FuseBox.import(FuseBox.mainFile);
63-
}
64-
if (!(data.path.indexOf('.html') >= 0)) return [3 /*break*/, 3];
65-
return [4 /*yield*/, this.context.handleViewChange(data.path)];
66-
case 2:
67-
_a.sent();
68-
return [2 /*return*/, true];
69-
case 3:
70-
moduleId = data.path.substr(0, data.path.length - 3);
71-
return [4 /*yield*/, this.context.handleModuleChange(moduleId, {})];
72-
case 4:
73-
_a.sent();
74-
return [2 /*return*/, true];
75-
case 5: return [2 /*return*/, false];
12+
if (this.reloadPageOnly) {
13+
clearTimeout(this.timer);
14+
this.timer = setTimeout(function () {
15+
document.location.reload();
16+
}, 250);
17+
}
18+
else {
19+
if (data.type === 'js') {
20+
FuseBox.flush();
21+
FuseBox.dynamic(data.path, data.content);
22+
if (FuseBox.mainFile) {
23+
FuseBox.import(FuseBox.mainFile);
24+
}
25+
if (data.path.indexOf('.html') >= 0) {
26+
this.context.handleViewChange(data.path);
27+
return true;
7628
}
77-
});
78-
});
29+
else {
30+
if (data.path.indexOf('.css') >= 0) {
31+
this.loader.moduleRegistry[data.path] = true;
32+
this.context.reloadCss(data.path);
33+
return true;
34+
}
35+
else {
36+
var moduleId = data.path.substr(0, data.path.length - 3);
37+
this.context.handleModuleChange(moduleId, {});
38+
return true;
39+
}
40+
}
41+
}
42+
}
43+
return false;
7944
};
8045
return FuseBoxAureliaHmrPlugin;
8146
}());

src/fuse-box-aurelia-hmr-plugin.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ export class FuseBoxAureliaHmrPlugin {
77
private context: any;
88
private reloadPageOnly: boolean;
99
private timer: number;
10+
private loader: any;
1011
constructor(loader: FuseBoxAureliaLoader, reloadPageOnly: boolean) {
1112
if (!reloadPageOnly) {
1213
// no need to have this if they are using the reload only
1314
let HmrContext = require('aurelia-hot-module-reload').HmrContext;
1415
this.context = new HmrContext(loader);
16+
this.loader = loader;
1517
}
1618
this.reloadPageOnly = reloadPageOnly;
1719
}
1820

19-
public async hmrUpdate(data: any): Promise<boolean> {
21+
public hmrUpdate(data: any): boolean {
2022

2123
if (this.reloadPageOnly) {
2224

@@ -39,12 +41,18 @@ export class FuseBoxAureliaHmrPlugin {
3941

4042
// call Aurelia HMR module
4143
if (data.path.indexOf('.html') >= 0) {
42-
await this.context.handleViewChange(data.path);
44+
this.context.handleViewChange(data.path); // <- returns promise...
4345
return true;
4446
} else {
45-
let moduleId = data.path.substr(0, data.path.length - 3); // remove .js
46-
await this.context.handleModuleChange(moduleId, {});
47-
return true;
47+
if (data.path.indexOf('.css') >= 0) {
48+
this.loader.moduleRegistry[data.path] = true; // need to have this module without css-resouses!
49+
this.context.reloadCss(data.path);
50+
return true;
51+
} else {
52+
let moduleId = data.path.substr(0, data.path.length - 3); // remove .js
53+
this.context.handleModuleChange(moduleId, {}); // <- returns promise...
54+
return true;
55+
}
4856
}
4957
}
5058
}

0 commit comments

Comments
 (0)