Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
0wain committed Nov 22, 2023
1 parent 0800d61 commit 8496fc0
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ const Plugin = function (Alpine) {
},
]

// Regiter all the aliases
methods.forEach((type) => {
Alpine.directive(type.directive, (el, { expression }, { evaluate, cleanup }) => {
directiveSetup({el, method: type.method, expression, evaluate})
let data = evalExpression(expression, evaluate);

el.addEventListener('click', () => {
processRequest({
el,
method: type.method,
...data
});
})
cleanup(() => observer.disconnect())
})
Alpine.magic(type.directive, (el, { evaluate }) => expression =>{
Expand All @@ -25,19 +34,6 @@ const Plugin = function (Alpine) {
});



function directiveSetup({el, method, expression, evaluate}) {
let data = evalExpression(expression, evaluate);

el.addEventListener('click', () => {
processRequest({
el,
method,
...data
});
})
}

function processRequest({el, method, route, headers, body}) {
console.log({el, method, route, headers, body});
// Make the request
Expand Down Expand Up @@ -72,6 +68,7 @@ const Plugin = function (Alpine) {
})
}

// Used to convert input string to object
function evalExpression(expression, evaluate) {
let data = {}

Expand Down

0 comments on commit 8496fc0

Please sign in to comment.