Closed cyfung1031 closed 1 year ago
Differentiating behavior through document.currentScript
is an antipattern for a variety of reasons. It breaks with bundles, it breaks if authors rename a script, and it breaks in a variety of contexts that don't have document.currentScript
defined (e.g. modules).
Bliss Full vs Bliss Shy - document.currentScript
When I saw Bliss Full and Bliss Shy, I thought their difference is as huge as jQuery and jQuery Slim, but actually they are almost the same.
I think it is better to merge as one with url search option in
document.currentScript
.The similar implementation is already found in Author's another JavaScript
I think "bliss.min.js?with=_" is most useful to me which is between Bliss and Bliss Shy.
Besides, event hijack and
clone()
shall be not used in the future. If the developer uses Bliss and want to keep tracing event listeners, he should use element._.bind instead. Forclone()
, it is already deprecated.Event Hijack is against the selling point of BlissJS - pollution to Vanilla JS
The disadvantages for the event hijack:
EventTarget.prototype.addEventListener
is notHTMLElement.prototype.addEventListener
HTMLDocument, HTMLElement, Node are ONLY EXAMPLES ofEventTarget
(eg. database object) That's why there are many issues opened for such a hijack. If some plugins use HTMLElement.prototype.addEventListener to create another hijack, Bliss's hijack will be overrided.addEventListener
is called frequently in some libraries / frameworks There is no point to store EVERY event handler! This causes memory increment and browser performance reduction.unbind
- don't led by the poor design of the native API. It is costly operation to do double looping withsplice
for every unbind.In short, the node clone with event listeners shall be the duty of browser's native API. This shall not be the job done by a lightweight JavaScript Library. (W3C insists not to implement
getEventListeners()
out of DevTools)The developers are not expected to have any hijack to vanilla JS except
_
.In Bliss Shy,
$.listeners
shall benull
and skip that in.bind()
and.unbind()
If the developer chooses "bliss.min.js?with=_" (or Bliss Shy), there is no point to store event listeners.