bigskysoftware / idiomorph

A DOM-merging algorithm
BSD 2-Clause "Simplified" License
631 stars 31 forks source link

htmx extension without globals #38

Open silverwind opened 4 months ago

silverwind commented 4 months ago

The htmx init code here relies on a htmx global: https://github.com/bigskysoftware/idiomorph/blob/8e40c42cc573609eb6863e72fa3403574974dd7d/src/idiomorph-htmx.js#L12

While reliance on globals is probably okay with <script> usage, in a scenario with a bundler it is not necessary and undesired to have any globals. How about allowing something like this?

import htmx from 'htmx.org';
import idiomorph from 'idiomorph/dist/idiomorph-ext-bundler.min.js';
htmx.defineExtension('morph', idiomorph);

Related: https://github.com/bigskysoftware/htmx/issues/1690