-
Notifications
You must be signed in to change notification settings - Fork 19
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
Refactor state #414
Merged
Merged
Refactor state #414
Conversation
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
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #414 +/- ##
==========================================
- Coverage 84.08% 83.08% -1.00%
==========================================
Files 178 185 +7
Lines 23183 24899 +1716
==========================================
+ Hits 19494 20688 +1194
- Misses 3689 4211 +522
☔ View full report in Codecov by Sentry. |
M-Adoo
force-pushed
the
refactor-state
branch
6 times, most recently
from
August 21, 2023 07:11
6707b1b
to
b0391a5
Compare
M-Adoo
force-pushed
the
refactor-state
branch
5 times, most recently
from
August 28, 2023 06:31
a06dc9a
to
7baecbf
Compare
M-Adoo
force-pushed
the
refactor-state
branch
8 times, most recently
from
September 8, 2023 15:36
171892c
to
bee3286
Compare
M-Adoo
force-pushed
the
refactor-state
branch
5 times, most recently
from
September 11, 2023 07:52
dea0c1a
to
98ca62c
Compare
…os, more flexible and consistent.
M-Adoo
force-pushed
the
refactor-state
branch
2 times, most recently
from
September 12, 2023 01:57
6d38da8
to
95c3fc2
Compare
M-Adoo
force-pushed
the
refactor-state
branch
from
September 12, 2023 02:13
95c3fc2
to
7ebac04
Compare
wjian23
approved these changes
Sep 12, 2023
sologeek
approved these changes
Sep 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request contains two parts refactoring and adding new features.
The new syntax
id
) in its expression. But the new syntax needs to usepipe!
to wrap the expression to subscribe to the state modified. The old syntax is implicit, the new syntax must explicitly subscribe.the old syntax:
the new syntax:
The key macros of the new syntax:
set_build_ctx!(ctx)
: use to set the build context, let the subsequent code can usectx!()
to access the build context.ctx!()
: use to access the build context anywhere if the build context is set byset_build_ctx!(ctx)
in this scope.rdl! {}
macro and@
symbol: used to declare an object. must used afterset_build_ctx!(ctx)
called.@
is a shortcut forrdl! {}
infn_widget
,rdl!
andpipe!
.$
symbol: get a reference of the state, supported infn_widget
,rdl!
andpipe!
.pipe!
: use to create a continuous value, for a widget or a field of an object that wants to keep update with an expression.fn_widget
: a macro to create aFnWidget
, and callset_build_ctx!
at the beginning of the function body.The state reader, writer and state hierarchy
We use
into_readonly
andinto_writeable
to do a little read-write distinction before, but it is not enough. Now, we introducedStateReader
andStateWriter
. A state without a writer will cancel all subscriptions on it because no one can modify it.Also introduced the state hierarchy in this state. The state always thinks as a whole before, when we need part of the state, it needs a little trick: introduce a new state and subscribe to the original map in some way.
Now, we have three convenient methods to create a new state from the original state:
StateReader::map_reader
to create a new read state from the original state, it shares the same data and notify with the original state.StateReader::map_writer
to create a new write state from the original state, it shares the same data and notify with the original state.StateReader::split_writer
to create a new read-write state from the original state, it shares the same data with the original but has its own notify.