Skip to content

Commit

Permalink
dom swapping test
Browse files Browse the repository at this point in the history
  • Loading branch information
maddalax committed Sep 22, 2024
1 parent 9e44fb5 commit 5c528f9
Show file tree
Hide file tree
Showing 18 changed files with 1,490 additions and 21 deletions.
562 changes: 561 additions & 1 deletion framework/assets/dist/htmgo.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions framework/assets/js/htmgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./htmxextensions/response-targets";
import "./htmxextensions/mutation-error";
import "./htmxextensions/livereload"
import "./htmxextensions/htmgo";
import "./htmxextensions/diffdomswap"

function watchUrl(callback: (oldUrl: string, newUrl: string) => void) {
let lastUrl = window.location.href;
Expand Down
23 changes: 23 additions & 0 deletions framework/assets/js/htmxextensions/diffdomswap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import htmx from "htmx.org";
import Idiomorph from './../idiomorph.js'

// @ts-ignore
htmx.defineExtension('diffdom-swap', {
isInlineSwap: function(swapStyle) {
return swapStyle === 'diffdom'
},
// @ts-ignore
handleSwap: function(swapStyle: string, target: any, fragment: any) {
if (swapStyle === 'diffdom') {
if (fragment.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
console.log('diffdom swap', target, fragment)
console.log(Idiomorph.morph(target, fragment.firstElementChild))
return [target]
} else {
console.log('diffdom swap', target, fragment)
console.log(Idiomorph.morph(target, fragment.outerHTML))
return [target]
}
}
}
})
Loading

0 comments on commit 5c528f9

Please sign in to comment.