pcui icon indicating copy to clipboard operation
pcui copied to clipboard

Rename pcui-binding namespace

Open slimbuck opened this issue 3 years ago • 2 comments

Perhaps I am doing it wrong, but referencing pcui-binding module from an application is cumbersome because the dash is treated as a symbol in JS and so instead of doing the following:

const t = new pcui-binding.Observer(...);

we are forced to do:

const t = new window['pcui-binding'].Observer(...);

Can we remove the dash from the module name please?

slimbuck avatar May 16 '21 08:05 slimbuck

Why can't this just live in the vanilla pcui namespace?

willeastcott avatar Jun 14 '21 10:06 willeastcott

Why can't this just live in the vanilla pcui namespace?

I see two potential solutions with this approach:

  1. Merge pcui and pcui-binding via webpack (I don't see any namespace clashes) Upside: simple/short pcui namespace Downside: Add 110kb (unzipped) for some people that don't require it

  2. Keep the webpack separation and just edit dist/pcui-binding.js after its generation, to add a one-liner at the header somewhere after factory() got called:

pcui && Object.assign(pcui, window['pcui-binding']);

(1) is adding 110kb extra and (2) feels a bit hacky, maybe a third approach could be to just add another webpack target which combines pcui and pcui-binding into dist/pcuiPlusBinding.js again.

In the meantime, everyone can just choose what fits them best:

(1)

<script src='http://127.0.0.1/pcui-review/dist/pcui.js'></script>
<script src='http://127.0.0.1/pcui-review/dist/pcui-binding.js'></script>
<script>
  // Make a pcuiBinding shortcut
  window.pcuiBinding = window['pcui-binding'];
</script>

(2)

<script src='http://127.0.0.1/pcui-review/dist/pcui.js'></script>
<script src='http://127.0.0.1/pcui-review/dist/pcui-binding.js'></script>
<script>
  // Augment pcui with pcui-binding classes
  Object.assign(pcui, window['pcui-binding']);
</script>

With this kind of programmatic solution one can also of course just do both:

(1) + (2)

<script src='http://127.0.0.1/pcui-review/dist/pcui.js'></script>
<script src='http://127.0.0.1/pcui-review/dist/pcui-binding.js'></script>
<script>
  // Make a pcuiBinding shortcut
  window.pcuiBinding = window['pcui-binding'];
  // Augment pcui with pcui-binding classes
  Object.assign(pcui, window['pcui-binding']);
</script>

kungfooman avatar Jun 14 '21 14:06 kungfooman

Closing this as the binding classes have been moved to the pcui namespace.

ellthompson avatar Dec 16 '22 11:12 ellthompson