Oluwasetemi / Oluwasetemi/javascript-note
Enhancement: Add magic-move animation for logical AND to optional chaining transition on page 21
Nobody has claimed this yet.
- Dominant language
- Vue
- Stars
- 5
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Enhancement Description
Page 21 of the JavaScript Note shows the comparison between using logical AND (&&) for null checking versus using optional chaining (?.). This would be an excellent opportunity to use Slidev's magic-move animation to visually demonstrate the transformation from the verbose approach to the cleaner syntax.
Location
- File:
pages/fundamentals.md - Section: Nullish Coalescing ?? and Optional Chaining ?.
- Lines: 453-461
- URL: https://javascript.oluwasetemi.dev/21
Current Implementation
The code currently shows both approaches separately without animation:
if (user && user.address && user.address.street) {
// console.log(user.address.street);
}
// console.log(user?.address?.street);
Proposed Enhancement
Use Slidev's magic-move feature to create an animated transition showing how the verbose logical AND approach transforms into the concise optional chaining syntax.
Implementation Approach
Use Slidev's magic-move syntax to split this into animated code blocks:
Option 1: Using magic-move directive
Create two sequential code blocks that will animate the transformation:
- First block shows the verbose logical AND checking
- Second block shows the cleaner optional chaining syntax
- Magic-move will animate the transition between them
Example structure:
````md magic-move
First code block with logical AND approach
Second code block with optional chaining approach
\````
Code Example
Before (verbose with logical AND):
if (user && user.address && user.address.street) {
console.log(user.address.street);
}
After (clean with optional chaining):
console.log(user?.address?.street);
Benefits
- Visual Learning: Students can see the transformation happen in real-time
- Comparison Clarity: The animation emphasizes the simplification that optional chaining provides
- Engagement: Makes the learning experience more interactive and memorable
- Best Practice: Demonstrates Slidev's powerful animation features for teaching programming concepts
Implementation Steps
- Locate lines 453-461 in
pages/fundamentals.md - Restructure the code example to use magic-move syntax
- Add descriptive comments to both code versions
- Test the animation in the Slidev presentation
- Ensure smooth transition between the two approaches
References
- Slidev Magic Move Documentation: https://sli.dev/guide/animations.html#magic-move, https://sli.dev/features/shiki-magic-move#shiki-magic-move
- Current page: https://javascript.oluwasetemi.dev/21
Additional Notes
- Consider uncommenting the console.log statements (as noted in Issue #46 and #47) when implementing this enhancement to show actual executable code examples
- This enhancement aligns with modern JavaScript teaching practices by visually demonstrating code evolution
- The animation will help students understand why optional chaining is preferred over verbose logical AND chains
Related Issues
- Issue #47 (Code block formatting on page 14)
- Issue #46 (Unnecessary comments before alert/prompt/confirm)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open pages/fundamentals.md around lines 453-461 in the Nullish Coalescing and Optional Chaining section, then review the Slidev Magic Move documentation linked in the issue. Restructure the two shown examples into an animated transition, preserve the explanatory comments, and verify the result on page 21 in the Slidev presentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- content
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100