Skip to content

Commit

Permalink
refactor: clean up the directive
Browse files Browse the repository at this point in the history
  • Loading branch information
iniznet committed Feb 18, 2023
1 parent 214f5f4 commit e745857
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"author": "Yusuf Fauzan",
"license": "MIT",
"repository": "https://github.com/iniznet/alpinejs-flux.git",
"module": "dist/flux.esm.js",
"unpkg": "dist/flux.min.js",
"scripts": {
Expand Down
8 changes: 3 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ export default function ( Alpine, Config ) {

Alpine.directive( "flux", ( el, { expression }, { evaluate } ) => {
const arrayOrTemplateName = evaluate( expression );
const template =
( Array.isArray( arrayOrTemplateName )
? arrayOrTemplateName
: Config[arrayOrTemplateName] ) || null;
const templateName = Array.isArray( arrayOrTemplateName ) ? "" : arrayOrTemplateName;
const template = templateName ? Config[templateName] : arrayOrTemplateName;

applyTransitions( el, arrayOrTemplateName, template );
applyTransitions( el, templateName, template );
} ).before( "transition" );

for ( const templateName of Object.keys( Config ) ) {
Expand Down

0 comments on commit e745857

Please sign in to comment.