Skip to content

Commit ba491aa

Browse files
committed
feat(core registry): Notify when all patterns are loaded and initialized.
1 parent 3d05847 commit ba491aa

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/core/registry.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
import $ from "jquery";
2020
import dom from "./dom";
21+
import events from "./events";
2122
import logging from "./logging";
2223
import utils from "./utils";
2324

@@ -150,7 +151,7 @@ const registry = {
150151
return patterns;
151152
},
152153

153-
scan(content, patterns, trigger) {
154+
async scan(content, patterns, trigger) {
154155
if (!content) {
155156
return;
156157
}
@@ -205,12 +206,25 @@ const registry = {
205206
});
206207

207208
// walk list backwards and initialize patterns inside-out.
209+
const pattern_instances = [];
208210
for (const el of matches.reverse()) {
209211
for (const name of patterns) {
210-
this.initPattern(name, el, trigger);
212+
pattern_instances.push(this.initPattern(name, el, trigger));
211213
}
212214
}
215+
216+
// Notify for all patterns loaded.
217+
document.dispatchEvent(
218+
new Event("patterns-loaded")
219+
);
213220
document.body.classList.add("patterns-loaded");
221+
222+
// Notify for all Patterns initialized.
223+
await Promise.all(pattern_instances);
224+
document.dispatchEvent(
225+
new Event("patterns-initialized")
226+
);
227+
document.body.classList.add("patterns-initialized");
214228
},
215229

216230
register(pattern, name) {

0 commit comments

Comments
 (0)