-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: Save the last selected rule. #64
Conversation
WalkthroughThe changes introduce a new feature flag "Storage" in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- Cargo.toml (1 hunks)
- src/lib.rs (2 hunks)
- static/scripts/editor.ts (3 hunks)
Additional comments not posted (6)
Cargo.toml (1)
33-33
: LGTM!The addition of the "Storage" feature flag to the
web-sys
dependency is a valid change that enables storage capabilities, which aligns with the PR objective of saving the last selected rule usinglocal_storage
.static/scripts/editor.ts (3)
20-20
: LGTM!The code changes are approved.
150-153
: LGTM!The code changes are approved.
195-195
: LGTM!The code changes are approved.
src/lib.rs (2)
44-50
: LGTM!The code changes are approved.
332-335
: Verify the global variable usage in the codebase.Ensure that all usages of the
LAST_SELECTION
global variable are safe and consistent with the new behavior.Run the following script to verify the global variable usage:
Verification successful
Global variable usage is safe and consistent.
The
LAST_SELECTION
global variable is used withinunsafe
blocks, ensuring safe access and modification. The changes do not negatively impact other parts of the codebase.
LAST_SELECTION
is declared asstatic mut
and accessed withinunsafe
blocks.- All usages are consistent with Rust's safety requirements for mutable static variables.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of the `LAST_SELECTION` global variable are safe and consistent. # Test: Search for the global variable usage. Expect: Only occurrences within unsafe blocks. rg --type rust -A 5 $'LAST_SELECTION'Length of output: 813
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- static/scripts/editor.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- static/scripts/editor.ts
Why not just save and load sate in JavaScript? There is no reason to manage storage in Wasm, it will complicate things. |
Even if you set the selected rule in javascript, it will be reset in the wasm module here: Line 289 in cff773b
|
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.
I have run it in local, it looks work will.
Would it make sense to use session storage instead of local storage? |
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.
Actionable comments posted: 0
session storage will get cleared after the browser restarts which will reset the selected rule again, while local storage will persist. Maybe I don't I understand your point though. |
This is a playground so it doesn't make too much sense for the info to persist across sessions. Also, will this PR include share URL support? |
The grammar and the input are stored in local storage, that's why I think selected rules also should be stored in local storage. No This PR doesn't include share URL support, but it will be easy to implement with the saved selected rule. |
Thanks for this contribution @omer-biz ! |
This address the issue I created earlier #63.
I ended up using
local_storage
to solve this which meant I had to enable theStorage
feature onweb_sys
which on my system add1kb
to the wasm module.Summary by CodeRabbit
New Features
Bug Fixes