Skip to content

Commit c357b23

Browse files
committed
feat(core registry): Implement sort_early Pattern option.
When scanning a document for patterns, resort patterns and set those with a sort_early property to the beginning of the initialization chain. NOTE: Only use when necessary. It's not guaranteed that a pattern with sort_early is set before another pattern with sort_early. Patterns which are registered later will have a higher chance to be sorted before others. Last come, first serve.
1 parent 61953d8 commit c357b23

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/core/registry.js

+11
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,24 @@ const registry = {
133133
},
134134

135135
orderPatterns(patterns) {
136+
// Resort patterns and set those with `sort_early` to the beginning.
137+
// NOTE: Only use when necessary and it's not guaranteed that a pattern
138+
// with `sort_early` is set to the beginning. Last come, first serve.
139+
for (const name of [...patterns]) {
140+
if (registry[name]?.sort_early) {
141+
patterns.splice(patterns.indexOf(name), 1);
142+
patterns.unshift(name);
143+
}
144+
}
145+
136146
// Always add pat-validation as first pattern, so that it can prevent
137147
// other patterns from reacting to submit events if form validation
138148
// fails.
139149
if (patterns.includes("validation")) {
140150
patterns.splice(patterns.indexOf("validation"), 1);
141151
patterns.unshift("validation");
142152
}
153+
143154
// Add clone-code to the very beginning - we want to copy the markup
144155
// before any other patterns changed the markup.
145156
if (patterns.includes("clone-code")) {

0 commit comments

Comments
 (0)