Skip to content

Commit 5f844c7

Browse files
docs: correct loaded() - server-side only, not a client-side hook (#361)
Document that loaded() belongs to node_helper, not Module. Add async/Promise support to the start() docs as the correct way to handle asynchronous module initialization.
1 parent db11193 commit 5f844c7

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

module-development/core-module-file.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,32 @@ requiresVersion: "2.1.0",
8686
This method is called when a module gets instantiated. In most cases you do not
8787
need to subclass this method.
8888

89-
### `loaded(callback)`
89+
### `start()`
9090

91-
_Introduced in version: 2.1.1._
91+
This method is called when all modules are loaded and the system is ready to
92+
boot up. Keep in mind that the dom object for the module is not yet created. The
93+
start method is a perfect place to define any additional module properties.
9294

93-
This method is called when a module is loaded. Subsequent modules in the config
94-
are not yet loaded. The `callback` function MUST be called when the module is
95-
done loading. In most cases you do not need to subclass this method.
95+
This method can be `async` or return a `Promise`. The system will wait for all
96+
modules' `start()` promises to settle (via `Promise.allSettled`) before
97+
proceeding to create the DOM and call `getDom()`. This makes it the right place
98+
for any asynchronous initialization, such as waiting for Web Components to be
99+
registered.
96100

97101
**Example:**
98102

99103
```js
100-
loaded: function(callback) {
101-
this.finishLoading();
102-
Log.log(this.name + ' is loaded!');
103-
callback();
104+
start: function() {
105+
this.mySpecialProperty = "So much wow!";
106+
Log.log(this.name + ' is started!');
104107
}
105108
```
106109

107-
### `start()`
108-
109-
This method is called when all modules are loaded and the system is ready to
110-
boot up. Keep in mind that the dom object for the module is not yet created. The
111-
start method is a perfect place to define any additional module properties:
112-
113-
**Example:**
110+
**Async example:**
114111

115112
```js
116-
start: function() {
117-
this.mySpecialProperty = "So much wow!";
113+
async start() {
114+
await customElements.whenDefined("my-custom-element");
118115
Log.log(this.name + ' is started!');
119116
}
120117
```

module-development/node-helper.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ requiresVersion: "2.1.0",
9090
This method is called when a node helper gets instantiated. In most cases you do
9191
not need to subclass this method.
9292

93+
### `loaded()`
94+
95+
_Introduced in version: 2.1.1._
96+
97+
This method is called after the node helper is loaded and its `name` and `path`
98+
properties have been set, but before `start()` is called. In most cases you do
99+
not need to subclass this method.
100+
93101
### `start()`
94102

95103
This method is called when all node helpers are loaded and the system is ready

0 commit comments

Comments
 (0)