pcui
pcui copied to clipboard
Rename pcui-binding namespace
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?
Why can't this just live in the vanilla pcui
namespace?
Why can't this just live in the vanilla
pcui
namespace?
I see two potential solutions with this approach:
-
Merge
pcui
andpcui-binding
via webpack (I don't see any namespace clashes) Upside: simple/shortpcui
namespace Downside: Add 110kb (unzipped) for some people that don't require it -
Keep the webpack separation and just edit
dist/pcui-binding.js
after its generation, to add a one-liner at the header somewhere afterfactory()
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>
Closing this as the binding classes have been moved to the pcui namespace.