-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define template inside $flux magic
- Loading branch information
Showing
7 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import applyTransitions from "./applyTransitions"; | ||
|
||
export default function (Alpine, validName, templateName, template = null) { | ||
Alpine.magic( validName, ( el ) => () => { | ||
applyTransitions( el, templateName, template ); | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
import applyTransitions from "./core/applyTransitions"; | ||
import parseTransitions from "./core/parseTransitions"; | ||
import registerMagic from "./core/registerMagic"; | ||
import convertCamelCase from "./utils/convertCamelCase"; | ||
|
||
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 transitions = parseTransitions( arrayOrTemplateName, template ); | ||
( Array.isArray( arrayOrTemplateName ) | ||
? arrayOrTemplateName | ||
: Config[arrayOrTemplateName] ) || null; | ||
|
||
applyTransitions( el, arrayOrTemplateName, transitions ) | ||
applyTransitions( el, arrayOrTemplateName, template ); | ||
} ).before( "transition" ); | ||
|
||
for ( const templateName of Object.keys( Config ) ) { | ||
const validName = convertCamelCase( templateName ); | ||
const template = Config[templateName] || null; | ||
|
||
Alpine.magic( validName, ( el ) => () => { | ||
const template = Config[templateName] || null; | ||
const transitions = parseTransitions( templateName, template ); | ||
|
||
applyTransitions( el, templateName, transitions ) | ||
} ); | ||
registerMagic( Alpine, validName, templateName, template ); | ||
} | ||
|
||
Alpine.magic( 'flux', ( el ) => ( templateName = '' ) => { | ||
const template = Config[templateName] || null; | ||
const transitions = parseTransitions( templateName, template ); | ||
Alpine.magic( | ||
"flux", | ||
( el ) => | ||
( templateName = "", newTemplate = null, applyToElement = true ) => { | ||
if ( newTemplate ) { | ||
const validName = convertCamelCase( templateName ); | ||
|
||
Config[templateName] = newTemplate; | ||
registerMagic( Alpine, validName, templateName, newTemplate ); | ||
} | ||
|
||
applyTransitions( el, templateName, transitions ) | ||
} ); | ||
if ( !applyToElement ) { | ||
return; | ||
} | ||
|
||
const template = Config[templateName] || null; | ||
|
||
applyTransitions( el, templateName, template ); | ||
} | ||
); | ||
} |