Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1ea9ac2

Browse files
sokramontogeek
authored andcommitted
docs(api) Improve HMR documentation (#2190)
1 parent fbd6a15 commit 1ea9ac2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎src/content/api/hot-module-replacement.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if (module.hot) {
2323

2424
The following methods are supported...
2525

26+
## Module API
2627

2728
### `accept`
2829

@@ -35,6 +36,23 @@ module.hot.accept(
3536
)
3637
```
3738

39+
When using ESM `import` all imported symbols from `dependencies` are automatically updated. Note: The dependency string must match exactly with the `from` string in the `import`. In some cases `callback` can even be omitted. Using `require()` in the `callback` doesn't make sense here.
40+
41+
When using CommonJS you need to update dependencies manually by using `require()` in the `callback`. Omitting the `callback` doesn't make sense here.
42+
43+
### `accept` (self)
44+
45+
Accept updates for itself.
46+
47+
``` js
48+
module.hot.accept(
49+
errorHandler // Function to handle errors when evaluating the new version
50+
)
51+
```
52+
53+
When this module or dependencies are updated, this module can be disposed and re-evaluated without informing parents. This makes sense if this module has no exports (or exports are updated in another way).
54+
55+
The `errorHandler` is fired when the evaluation of this module (or dependencies) has thrown an exception.
3856

3957
### `decline`
4058

@@ -46,6 +64,17 @@ module.hot.decline(
4664
)
4765
```
4866

67+
Flag a dependency as not-update-able. This makes sense when changing exports of this dependency can be handled or handling is not implemented yet. Depending on your HMR management code an update to this dependencies (or unaccepted dependencies of it) usually causes a full-reload of the page.
68+
69+
### `decline` (self)
70+
71+
Reject updates for itself.
72+
73+
``` js
74+
module.hot.decline()
75+
```
76+
77+
Flag this module as not-update-able. This make sense when this module has inrevertable side-effects, or HMR handling is not implemented for this module yet. Depending on your HMR management code an update to this module (or unaccepted dependencies) usually causes a full-reload of the page.
4978

5079
### `dispose` (or `addDisposeHandler`)
5180

@@ -66,6 +95,7 @@ Remove the callback added via `dispose` or `addDisposeHandler`.
6695
module.hot.removeDisposeHandler(callback)
6796
```
6897

98+
## Management API
6999

70100
### `status`
71101

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /