Skip to content

Commit 6848e8b

Browse files
committed
fix bug adding items twice in hookRegistry under some circumstances
1 parent 615f864 commit 6848e8b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

index.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ export default {
1919

2020
for (let extensionName in options.extensions) {
2121
let extension = options.extensions[extensionName]
22-
if(extension.initialize){
22+
if(extension.initialize) {
2323
extension.initialize()
2424
}
2525
for (let hook in extension.hooks) {
26-
if (hookRegistry[hook] === undefined) {
27-
hookRegistry[hook] = Array.isArray(extension.hooks[hook])?
28-
extension.hooks[hook] : [extension.hooks[hook]]
29-
}
30-
// console.debug(extension.name + ": registering a component for hook '" + hook + "'")
26+
// make array
27+
let componentArray = Array.isArray(extension.hooks[hook]) ?
28+
extension.hooks[hook]
29+
: [extension.hooks[hook]]
3130

32-
// add extension's component(s) to registry
33-
if (Array.isArray(extension.hooks[hook])) {
34-
hookRegistry[hook].concat(extension.hooks[hook])
31+
if (hookRegistry[hook] === undefined) {
32+
hookRegistry[hook] = componentArray
3533
} else {
36-
hookRegistry[hook].push(extension.hooks[hook])
37-
}
34+
// if extension provides an array, merge it
35+
hookRegistry[hook] = hookRegistry[hook].concat(componentArray)
3836

37+
}
38+
// console.debug(`Registering component '${extensionName}' for hook '${hook}'`)
3939
}
4040
}
4141

@@ -46,6 +46,7 @@ export default {
4646
},
4747
computed: {
4848
extensions () {
49+
// console.log(`hook ${this.hook}: `, hookRegistry[this.hook])
4950
return hookRegistry[this.hook]
5051
}
5152
},

0 commit comments

Comments
 (0)