timekit-io/booking-js

Only one instance on a page will respond to callbacks

Opened this issue · 0 comments

If I'm rendering two instances of the widget on the page, I've found that only the second instance that was rendered will respond to callbacks.

I'm initializing them from two separate instances of a Stimulus controller. In short, there are two elements on the page that each have a data-controller attribute. That tells Stimulus to mount an instance of a controller onto them.

When the controllers connect, they each create a new TimekitBooking() and initialize it with similar configuration. Part of this configuration is a set of callbacks that call methods on the controller instance.

I'd expect that if two widgets were initialized with separate callbacks, each widget's callbacks would run when the corresponding widget receives the event. But it seems as though only the most recently initialized instance of the widget runs the callbacks.