Allow init() to be called multiple times for dynamically added elements
IlyasMakari opened this issue · 1 comments
Relevant file: https://github.com/scaleflex/js-cloudimage-360-view/blob/master/src/index.js
This issue has been submitted before but was incorrectly marked as 'duplicate' for a slightly related problem: #61
The issue
I noticed that this project doesn't work as expected when dynamically adding new viewers to the DOM.
In my case, new viewers could be added to the page at any time. However, currently window.CI360.init()
is only expected to be called exactly once. This means that no new viewers can be dynamically added after window.CI360.init()
has been called.
Temporary workaround
Every time a new viewer is added you can call window.CI360.destroy()
followed by window.CI360.init()
. However, this comes with a huge performance issue, because all the previous viewers need to be re-initialized.
Possible solution
Currently window.CI360.init()
will create an array of CI360Viewer
objects for all uninitialized viewers. Afterwards, this array replaces the current window.CI360._viewers
array. However, it would be better if this array was concatenated, like this:
window.CI360._viewers = window.CI360._viewers.concat(viewers);
This allows you to call window.CI360.init()
whenever new viewers need to be initialized, while still keeping all the currently initialized viewers.
Edit: It would also be nice if init()
could receive an argument to specify which uninitialized viewer should be initialized and added to the _viewers
array. This is useful because if you initialize a viewer that is invisible it creates issues
hey @IlyasMakari, thanks for your feedback
added in v2.7.9
please check add