Skip to content

Commit 2b45bbf

Browse files
sokraskipjack
authored andcommitted
docs(api): correct and improve hot-module-replacement (#1562)
Fix and improve HMR management API page. Watch status no longer exists. Add and elaborate on various new features.
1 parent 8b060b9 commit 2b45bbf

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ module.hot.status() // Will return one of the following strings...
7878
| ----------- | -------------------------------------------------------------------------------------- |
7979
| idle | The process is waiting for a call to `check` (see below) |
8080
| check | The process is checking for updates |
81-
| watch | The process is in watch mode and will be automatically notified about changes |
82-
| watch-delay | Delaying for a specified time after the initial change to allow for any other updates |
8381
| prepare | The process is getting ready for the update (e.g. downloading the updated module) |
8482
| ready | The update is prepared and available |
8583
| dispose | The process is calling the `dispose` handlers on the modules that will be replaced |
@@ -93,27 +91,60 @@ module.hot.status() // Will return one of the following strings...
9391
Test all loaded modules for updates and, if updates exist, `apply` them.
9492

9593
``` js
96-
module.hot.check(autoApply, (error, outdatedModules) => {
97-
// Catch errors and outdated modules...
98-
})
94+
module.hot.check(autoApply).then(outdatedModules => {
95+
// outdated modules...
96+
}).catch(error => {
97+
// catch errors
98+
});
9999
```
100100

101101
The `autoApply` parameter can either be a boolean or `options` to pass to the `apply` method when called.
102102

103103

104104
### `apply`
105105

106-
Continue the update process (as long as `module.hot.status() === 'ready').
106+
Continue the update process (as long as `module.hot.status() === 'ready'`).
107107

108108
``` js
109-
module.hot.apply(options, (error, outdatedModules) => {
110-
// Catch errors and outdated modules...
111-
})
109+
module.hot.apply(options).then(outdatedModules => {
110+
// outdated modules...
111+
}).catch(error => {
112+
// catch errors
113+
});
112114
```
113115

114116
The optional `options` object can include the following properties:
115117

116-
- `ignoreUnaccepted` (boolean): Continue the update process even if some modules are not accepted.
118+
- `ignoreUnaccepted` (boolean): Ignore changes made to unaccepted modules.
119+
- `ignoreDeclined` (boolean): Ignore changes made to declined modules.
120+
- `ignoreErrored` (boolean): Ignore errors throw in accept handlers, error handlers and while reevaulating module.
121+
- `onDeclined` (function(info)): Notifier for declined modules
122+
- `onUnaccepted` (function(info)): Notifier for unaccepted modules
123+
- `onAccepted` (function(info)): Notifier for accepted modules
124+
- `onDisposed` (function(info)): Notifier for disposed modules
125+
- `onErrored` (function(info)): Notifier for errors
126+
127+
The `info` parameter will be an object containing some of the following values:
128+
129+
``` js
130+
{
131+
type: "self-declined" | "declined" |
132+
"unaccepted" | "accepted" |
133+
"disposed" | "accept-errored" |
134+
"self-accept-errored" | "self-accept-error-handler-errored",
135+
moduleId: 4, // The module in question.
136+
dependencyId: 3, // For errors: the module id owning the accept handler.
137+
chain: [1, 2, 3, 4], // For declined/accepted/unaccepted: the chain from where the update was propagated.
138+
parentId: 5, // For declined: the module id of the declining parent
139+
outdatedModules: [1, 2, 3, 4], // For accepted: the modules that are outdated and will be disposed
140+
outdatedDependencies: { // For accepted: The location of accept handlers that will handle the update
141+
5: [4]
142+
},
143+
error: new Error(...), // For errors: the thrown error
144+
originalError: new Error(...) // For self-accept-error-handler-errored:
145+
// the error thrown by the module before the error handler tried to handle it.
146+
}
147+
```
117148

118149

119150
### `addStatusHandler`

0 commit comments

Comments
 (0)