I have a JS plugin in Shopware 6, that subscribes to two events of another JS plugin:
One that fires after the user interacts with the page and one that fires at the end of init()
.
The latter does nothing. I am confused, because the other event works just fine.
Both $emitter.publish
have the same argument. In my plugin, they use the same method:
// main.js
import MyPlugin from "./my-plugin/my-plugin.plugin";
const PluginManager = window.PluginManager;
PluginManager.register("MyPlugin", MyPlugin);
// ./my-plugin/my-plugin.plugin.js
import Iterator from "src/helper/iterator.helper";
export default class MyPlugin extends window.PluginBaseClass {
init() {
const configuratorPlugins =
window.PluginManager.getPluginInstances("TargetPlugin");
Iterator.iterate(configuratorPlugins, (instance) => {
// nope ...
instance.$emitter.subscribe("init", this.onEvent.bind(this));
// working ...
instance.$emitter.subscribe(
"otherEvent",
this.onEvent.bind(this)
);
});
}
onEvent(event) {
// do it ...
}
}
// target-plugin.plugin.js
init() {
// ...
this.$emitter.publish('init', this.createCurrentState());
}
The init
event is not inside an if statement. I tested this.createCurrentState()
with a console.log()
right before the event and that works.
Also, I looked into PluginManager.getPluginList()
. The other plugin is in the list before my plugin gets registered – if that helps.
Don’t know what I am doing wrong. That plugin is the only one which publishes an event inside init()
.