-
Notifications
You must be signed in to change notification settings - Fork 0
Feat #Async Block #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or 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
… starter async condition
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…h {} and {{}} syntax
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implementation Summary: The
{#async}Universal Block1. Feature: The
{#async}BlockThis document summarizes the completed implementation of a new, universal template block designed to handle both asynchronous value resolution and synchronous variable scoping with a single, elegant, and declarative API.
2. Core Philosophy & Value
let/aliasing with one construct, reducing the API surface area.{#async getUsers as users}reads naturally without redundancy.{before},{loading}) and ({error},{catch}) to allow developers to choose the term that best fits their mental model.3. Keyword API
{#async}letbehavior).{#async state.user.profile as profile}or{#async getUsers() as users}4. Syntax & Clauses
Main Clause (Success State)
{#async expression as alias}{#async expression as { prop1, prop2, ...rest }}{#async expression}asclause is provided, the resolved value is available via{this}.Sub-Clauses (Optional, Fixed Branches)
{before}and{loading}are interchangeable aliases.{error}(injects defaulterrorvariable) and{error as e}(custom alias).5. Implementation Architecture
AST Structure
template-compiler.jsparses the syntax into anasyncnode with dedicated, named properties for each optional clause. This is more precise and efficient for the renderer than a genericbranchesarray, as our clauses are fixed and not repeatable.{ "type": "async", "expression": "getUsers()", "as": "users", "parts": ["name", "email"], "rest": "otherProps", "content": [ /* Array of nodes for success state */ ], "loadingContent": [ /* Optional: Array of nodes for {before}/{loading} state */ ], "errorContent": [ /* Optional: Array of nodes for {error} state */ ], "errorAs": "e" // Optional: The alias for the error object }Compiler & Renderer Responsibility
template-compiler.jsparses the{#async}grammar into the standardasyncAST node.renderer.jsinterprets theasyncAST node, invokes the directive, and manages the creation of new data contexts for child templates, following the pattern established in the{#each}implementation.Reactivity & Runtime Logic
reactive-async.js).Reaction.create()to establish a reactive context, ensuring the block re-evaluates when signals in theexpressionchange.6. Key Implementation Details
parseAsyncString()that handles both the expression andasclause correctly.{error as e}syntax using a normalization approach in the compiler.Reaction.create()for automatic re-evaluation when expressions change.