Skip to content

Commit

Permalink
refactor: separate 'flux' magic from magic arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
iniznet committed Feb 16, 2023
1 parent a31659f commit ee1d073
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/flux.esm.js

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

2 changes: 1 addition & 1 deletion dist/flux.min.js

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

11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import parseTransitions from "./core/parseTransitions";
import convertCamelCase from "./utils/convertCamelCase";

export default function ( Alpine, Config ) {
const magicNames = ['flux', ...Object.keys( Config )];

Alpine.directive( "flux", ( el, { expression }, { evaluate } ) => {
const arrayOrTemplateName = evaluate( expression );
const template =
Expand All @@ -15,7 +13,7 @@ export default function ( Alpine, Config ) {
applyTransitions( el, arrayOrTemplateName, transitions )
} ).before( "transition" );

for ( const templateName of magicNames ) {
for ( const templateName of Object.keys( Config ) ) {
const validName = convertCamelCase( templateName );

Alpine.magic( validName, ( el ) => () => {
Expand All @@ -25,4 +23,11 @@ export default function ( Alpine, Config ) {
applyTransitions( el, templateName, transitions )
} );
}

Alpine.magic( 'flux', ( el ) => ( templateName = '' ) => {
const template = Config[templateName] || null;
const transitions = parseTransitions( templateName, template );

applyTransitions( el, templateName, transitions )
} );
}

0 comments on commit ee1d073

Please sign in to comment.