-
-
Notifications
You must be signed in to change notification settings - Fork 104
docs: add conceptual documentation for Stac Registry #473
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
+191
−58
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3086896
docs: add Stac Registry documentation
Shonu72 bf1b0d2
docs: refactor and improve stac_registry.mdx documentation with updat…
Shonu72 47bf8f8
chore: sync all pubspec.lock files
Shonu72 8c5f423
chore: sync lockfiles with Flutter 3.41.6
Shonu72 3f97dea
docs: update StacRegistry registration example to use positional argu…
Shonu72 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| --- | ||
| title: "Stac Registry" | ||
| description: "Understand the central hub for widget parsers, action parsers, and global state in the Stac ecosystem" | ||
| --- | ||
|
|
||
| The **Stac Registry** is the "brain" of the Stac framework. It acts as a centralized, in-memory repository that manages how the engine translates static JSON data into live Flutter widgets and functional actions. | ||
|
|
||
| ## 1. What is Stac Registry? | ||
|
|
||
| The Stac Registry is a singleton service that serves as a lookup table for the rendering engine. It manages three primary areas: | ||
| - **Widget Parsers**: Mapping of JSON `type` strings (e.g., `"text"`) to their respective `StacParser`. | ||
| - **Action Parsers**: Mapping of logic triggers (e.g., `"navigate"`) to their `StacActionParser`. | ||
| - **Global Variables**: A key-value store for placeholder resolution (e.g., `{{userName}}`). | ||
|
|
||
| ## 2. Why and when it should be used? | ||
|
|
||
| The Registry is used whenever you need to: | ||
| - **Extend Stac**: Register custom widget or action parsers that are not included in the core library. | ||
| - **Manage Dynamic Data**: Inject application state (like user info or theme settings) into your SDUI screens without re-fetching JSON. | ||
| - **Custom Logic**: Trigger specific application logic directly from a server-side payload. | ||
|
|
||
| ## 3. How it fits into Stac Architecture | ||
|
|
||
| The Registry acts as the bridge between **Server JSON** and **Native Flutter execution**. | ||
|
|
||
| ### Architecture Flow | ||
|
|
||
| ```mermaid | ||
| graph TD | ||
| A[Server JSON] --> B(Variable Resolver) | ||
| B --> C{Stac Registry} | ||
| C -->|Lookup Parser| D[Widget Parser] | ||
| C -->|Lookup Action| E[Action Parser] | ||
| D --> F[Native Flutter Widget] | ||
| E --> G[Logic Execution] | ||
| ``` | ||
|
|
||
| ### Data Flow Steps | ||
| 1. **Placeholder Resolution**: The `Variable Resolver` swaps any `{{variable}}` placeholders in the JSON with real values from the Registry. | ||
| 2. **Parser Discovery**: The Stac engine queries the Registry for the parser matching the JSON's `type` field. | ||
| 3. **Execution**: The found parser converts the JSON data into a Flutter widget or executes the requested action. | ||
|
|
||
| ## 4. Basic Usage Example | ||
|
|
||
| ### Registering a Custom Parser | ||
| You typically register your custom parsers during the application's initialization phase. | ||
|
|
||
| ```dart | ||
| void main() async { | ||
| await Stac.initialize( | ||
| parsers: [ | ||
| const MyCustomWidgetParser(), | ||
| ], | ||
| ); | ||
|
|
||
| runApp(const MyApp()); | ||
| } | ||
| ``` | ||
|
|
||
| ### Using Global Variables | ||
| Store a value in the Registry and reference it in your SDUI screens. | ||
|
|
||
| ```dart | ||
| // Set a global variable | ||
| StacRegistry.instance.setValue('userName', 'Alex Smith'); | ||
| ``` | ||
|
|
||
| **JSON Usage:** | ||
| ```json | ||
| { | ||
| "type": "text", | ||
| "data": "Welcome back, {{userName}}!" | ||
| } | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > **Variable Resolution is Recursive.** If you store a complex Map in the Registry, you can access nested properties in your JSON using dot notation (e.g., `{{user.profile.name}}`). | ||
|
|
||
| ### 5. Overriding Core Behavior (Global Styling) | ||
| If you want to change how a standard widget like `StacText` behaves globally (e.g., to force all text to be uppercase or add a custom logging interceptor), you can override the default parser. | ||
|
|
||
| ```dart | ||
| StacRegistry.instance.register( | ||
| const MyBrandedTextParser(), | ||
| true, // This replaces the core "text" parser | ||
| ); | ||
| ``` | ||
|
|
||
| > [!WARNING] | ||
| > **Memory Management.** Since the Registry is a Singleton, registrations and values persist for the entire lifecycle of the application. Always use `removeValue()` to clear sensitive user data when they log out to avoid memory leaks or data exposure. | ||
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StacRegistry.registeris declared as a positional optional second parameter, not a named parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shonu72, can you please check this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch! I've updated the sample code in stac_registry.mdx to correctly use a positional parameter for the override flag, matching the actual implementation of StacRegistry.register