Skip to content

Commit

Permalink
Merge pull request #81 from botandrose/prettier
Browse files Browse the repository at this point in the history
Add prettier to normalize code style
  • Loading branch information
1cg authored Dec 23, 2024
2 parents a42245d + 0fe1abc commit 2bc3a84
Show file tree
Hide file tree
Showing 14 changed files with 2,912 additions and 2,537 deletions.
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules/
dist/
coverage/
test/*/*
!test/lib
package.json
package-lock.json
tsconfig.json
*.md
.github

16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"gen-modules": "npm run-script amd && npm run-script cjs && npm run-script esm",
"dist": "cp -r src/* dist/ && cat src/idiomorph.js src/idiomorph-htmx.js > dist/idiomorph-ext.js && npm run-script gen-modules && npm run-script uglify && gzip -9 -k -f dist/idiomorph.min.js > dist/idiomorph.min.js.gz && exit",
"uglify": "uglifyjs -m eval -o dist/idiomorph.min.js dist/idiomorph.js && uglifyjs -m eval -o dist/idiomorph-ext.min.js dist/idiomorph-ext.js",
"format": "prettier --write .",
"format-check": "prettier --check .",
"typecheck": "tsc"
},
"repository": {
Expand All @@ -43,6 +45,7 @@
"fs-extra": "^9.1.0",
"htmx.org": "1.9.9",
"p-wait-for": "^5.0.2",
"prettier": "^3.4.2",
"sinon": "^9.2.4",
"typescript": "^5.3.3",
"uglify-js": "^3.15.0"
Expand Down
44 changes: 22 additions & 22 deletions src/idiomorph-htmx.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
(function(){
function createMorphConfig(swapStyle) {
if (swapStyle === 'morph' || swapStyle === 'morph:outerHTML') {
return {morphStyle: 'outerHTML'}
} else if (swapStyle === 'morph:innerHTML') {
return {morphStyle: 'innerHTML'}
} else if (swapStyle.startsWith("morph:")) {
return Function("return (" + swapStyle.slice(6) + ")")();
}
(function () {
function createMorphConfig(swapStyle) {
if (swapStyle === "morph" || swapStyle === "morph:outerHTML") {
return { morphStyle: "outerHTML" };
} else if (swapStyle === "morph:innerHTML") {
return { morphStyle: "innerHTML" };
} else if (swapStyle.startsWith("morph:")) {
return Function("return (" + swapStyle.slice(6) + ")")();
}
}

htmx.defineExtension('morph', {
isInlineSwap: function(swapStyle) {
let config = createMorphConfig(swapStyle);
return config?.morphStyle === "outerHTML" || config?.morphStyle == null;
},
handleSwap: function (swapStyle, target, fragment) {
let config = createMorphConfig(swapStyle);
if (config) {
return Idiomorph.morph(target, fragment.children, config);
}
}
});
})()
htmx.defineExtension("morph", {
isInlineSwap: function (swapStyle) {
let config = createMorphConfig(swapStyle);
return config?.morphStyle === "outerHTML" || config?.morphStyle == null;
},
handleSwap: function (swapStyle, target, fragment) {
let config = createMorphConfig(swapStyle);
if (config) {
return Idiomorph.morph(target, fragment.children, config);
}
},
});
})();
Loading

0 comments on commit 2bc3a84

Please sign in to comment.