LeaVerou / bliss

Blissful JavaScript
http://blissfuljs.com
MIT License
2.39k stars 104 forks source link

Event Hijack is against "Heavenly JavaScript!" - Bliss Full vs Bliss Shy #248

Closed cyfung1031 closed 1 year ago

cyfung1031 commented 3 years ago

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. For clone(), it is already deprecated.

Event Hijack is against the selling point of BlissJS - pollution to Vanilla JS

The disadvantages for the event hijack:

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 be null 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.

LeaVerou commented 3 years 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).