Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
215 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ "a": 1, "b": 1 } | ||
--- | ||
{ "a": 2, "b": 1 } | ||
--- | ||
{ "a": 2, "b": 2 } | ||
--- | ||
{ "a": 3, "b": 3 } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import "./data.json"; | ||
import mod1 from "./module1"; | ||
import mod2 from "./module2"; | ||
import { value1, value2 } from "./store"; | ||
|
||
it("should invalidate a self-accepted module", function(done) { | ||
expect(mod1).toBe(1); | ||
expect(mod2).toBe(1); | ||
expect(value1).toBe(1); | ||
expect(value2).toBe(1); | ||
let step = 0; | ||
module.hot.accept("./module1"); | ||
module.hot.accept("./module2"); | ||
module.hot.accept("./data.json", () => | ||
setTimeout(() => { | ||
switch (step) { | ||
case 0: | ||
step++; | ||
expect(mod1).toBe(1); | ||
expect(mod2).toBe(1); | ||
expect(value1).toBe(2); | ||
expect(value2).toBe(2); | ||
NEXT(require("../../update")(done)); | ||
break; | ||
case 1: | ||
step++; | ||
expect(mod1).toBe(2); | ||
expect(mod2).toBe(2); | ||
expect(value1).toBe(2); | ||
expect(value2).toBe(2); | ||
NEXT(require("../../update")(done)); | ||
break; | ||
case 2: | ||
step++; | ||
expect(mod1).toBe(3); | ||
expect(mod2).toBe(3); | ||
expect(value1).toBe(3); | ||
expect(value2).toBe(3); | ||
done(); | ||
break; | ||
default: | ||
done(new Error("should not happen")); | ||
break; | ||
} | ||
}, 100) | ||
); | ||
NEXT(require("../../update")(done)); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import data from "./data.json"; | ||
import { setValue1 } from "./store"; | ||
|
||
setValue1(data.a); | ||
|
||
export default data.b; | ||
|
||
if (module.hot.data && module.hot.data.ok && module.hot.data.b !== data.b) { | ||
module.hot.invalidate(); | ||
} else { | ||
module.hot.dispose(d => { | ||
d.ok = true; | ||
d.b = data.b; | ||
}); | ||
module.hot.accept(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import data from "./data.json"; | ||
import { setValue2 } from "./store"; | ||
|
||
setValue2(data.a); | ||
|
||
export default data.b; | ||
|
||
const b = data.b; | ||
|
||
module.hot.accept(["./data.json"], () => { | ||
if (data.b !== b) { | ||
module.hot.invalidate(); | ||
return; | ||
} | ||
setValue2(data.a); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export let value1 = 0; | ||
export function setValue1(v) { | ||
value1 = v; | ||
} | ||
|
||
export let value2 = 0; | ||
export function setValue2(v) { | ||
value2 = v; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function invalidate() { | ||
module.hot.invalidate(); | ||
} | ||
|
||
export const value = {}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function invalidate() { | ||
module.hot.invalidate(); | ||
} | ||
|
||
export const value = {}; | ||
|
||
module.hot.accept(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function invalidate() { | ||
module.hot.invalidate(); | ||
} | ||
|
||
export const value = module.hot.data ? module.hot.data.value : {}; | ||
|
||
module.hot.dispose(data => { | ||
data.value = value; | ||
}); | ||
|
||
module.hot.accept(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { a, b, c } from "./module"; | ||
|
||
it("should allow to invalidate and reload a file", () => { | ||
const oldA = a.value; | ||
const oldB = b.value; | ||
const oldC = c.value; | ||
expect(module.hot.status()).toBe("idle"); | ||
a.invalidate(); | ||
expect(module.hot.status()).toBe("ready"); | ||
b.invalidate(); | ||
expect(module.hot.status()).toBe("ready"); | ||
c.invalidate(); | ||
expect(module.hot.status()).toBe("ready"); | ||
module.hot.apply(); | ||
expect(module.hot.status()).toBe("idle"); | ||
expect(a.value).not.toBe(oldA); | ||
expect(b.value).not.toBe(oldB); | ||
expect(c.value).toBe(oldC); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as a from "./a"; | ||
import * as b from "./b"; | ||
import * as c from "./c"; | ||
|
||
export { a, b, c }; | ||
|
||
module.hot.accept(["./a", "./b", "./c"]); |