marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
141 stars 40 forks source link

Multiple bundled instances of marko-widgets on same page causes conflict #118

Closed philidem closed 8 years ago

philidem commented 8 years ago

I have a page that uses marko-widgets and also include a JavaScript API that also uses marko-widgets. This causes the same unique ID (e.g. wc0, wc1, etc.) to be generated for widgets on the client-side which breaks both applications.

philidem commented 8 years ago

There are two possible implementations to fix this that I think we should consider:

  1. The function that generates a unique ID should be stored as a global on the window object.
  2. Provide a require('marko-widgets').setWidgetIdPrefix(...) function.

After testing these two implementations, I am actually leaning toward implementing both. I don't think it hurts to give developers control over the ID prefix and since older builds of marko-widgets didn't use the shared global, there's no way to make sure your new project doesn't have a conflict (unless you rebuild the old project so that it uses the new marko-widgets after this fix).