-
Notifications
You must be signed in to change notification settings - Fork 0
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
Renaming & Refactoring #7
Conversation
packages/doenetml-worker-rust/lib-doenetml-core/src/core/components/common.rs
Show resolved
Hide resolved
packages/doenetml-worker-rust/lib-doenetml-core/src/core/components/doenet/boolean.rs
Show resolved
Hide resolved
BooleanState::get_value_dependency_instructions(), | ||
) | ||
.into(), | ||
value: BooleanStateVar::new_from_children().into(), |
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'm a little worried how BooleanStateVar
might be confused with StateVar<bool>
. It's interesting how you can BooleanStateVar.into()
to get a StateVar<bool>
.
I can't decide if this similarity is a good thing so authors just do this naturally, or if it will cause confusion.
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.
The nice thing about Rust is that the types are inescapable, so the type information should always be with the developer. We could import them as general_state_var::BooleanStateVar
if we really wanted to emphasize it.
...r-rust/lib-doenetml-core/src/core/components/doenet/text_input/state_vars/immediate_value.rs
Outdated
Show resolved
Hide resolved
...r-rust/lib-doenetml-core/src/core/components/doenet/text_input/state_vars/immediate_value.rs
Show resolved
Hide resolved
...r-rust/lib-doenetml-core/src/core/components/doenet/text_input/state_vars/immediate_value.rs
Show resolved
Hide resolved
...r-rust/lib-doenetml-core/src/core/components/doenet/text_input/state_vars/immediate_value.rs
Outdated
Show resolved
Hide resolved
packages/doenetml-worker-rust/lib-doenetml-core/src/core/dependency.rs
Outdated
Show resolved
Hide resolved
packages/doenetml-worker-rust/lib-doenetml-core/src/core/dependency.rs
Outdated
Show resolved
Hide resolved
packages/doenetml-worker-rust/lib-doenetml-core/src/core/general_state_var/boolean_state_var.rs
Show resolved
Hide resolved
packages/doenetml-worker-rust/lib-doenetml-core/src/core/general_state_var/boolean_state_var.rs
Outdated
Show resolved
Hide resolved
packages/doenetml-worker-rust/lib-doenetml-core/src/core/state/state_var.rs
Outdated
Show resolved
Hide resolved
/// the dependencies directly on the the structure (`self`) | ||
/// in a form (presumably typed not with enums) for efficient calculation. | ||
/// Called when data queries for the state variable have been completed. | ||
/// State variables are expected to cache the results of their queries |
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.
Maybe "State variables must cache...", as "expected to" sounds like it might be optional to me.
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 guess the types might be hard to figure out, but this bit bothered me...it seems like core should cache the results and send them to the component when they're needed...
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.
Yeah, in the Javascript code, core does the caching. I did this solely for the typing, to avoid unwrapping enums on every cycle. Maybe a silly optimization that we can revisit with profiling.
packages/doenetml-worker-rust/lib-doenetml-core/src/core/state/state_var_calculations.rs
Outdated
Show resolved
Hide resolved
@@ -606,3 +599,6 @@ pub fn add_dependency_data_impl(_attr: TokenStream, item: TokenStream) -> TokenS | |||
_ => panic!("`add_standard_component_fields` has to be used with structs."), | |||
} | |||
} | |||
|
|||
#[cfg(test)] |
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.
Is this doing something other than reminding us to write tests?
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.
No, just a reminder. I almost wrote some tests, but then got distracted...
more renaming of state to props
This PR primarily introduces new naming conventions with the goal of making it easier for other developers writing components.
The proposed (and included) changes are:
DependencyInstruction
->DataQuery
. ADependencyInstruction
is called anInstruction
because it instructs Core how to get the data it wants. Another name for this is a query. Query sounds more transparent to me because a developer doesn't really care what core does/how it does it. They just want the answer to their question, which is: "what is the data that satisfies these restrictions?"New convention:
RequiredData
. Suppose we're authoring theFoo
state variable. Instead of defining a structureFooDependencies
and havingFooDependencyInstructions
automatically created, a developer creates a private structRequiredData
andRequiredDataGraphQueries
is automatically created.Motivation: Using a uniform name will make state var files look more similar and will hopefully make them easier to follow, since they will have very similar structures. We also have used the word
Dependency
for several things.FooDependencies
could be interpreted as describing graph queries or as describing theStateVarPointer
s or as describing the data that has been retrieved by core. Calling itRequiredData
makes it clear that it is 1) required for computation, and 2) is data and not pointers/requests.dependency_values
->query_results
. This could have other names, likerequired_data_cache
or justrequired_data
. This is set after core executes aGraphQuery
, so I named itquery_results
, but this could be a bad name becausequery_results
could be populated by default values (and used before core has done anything?)StateVarInterface
->StateVarUpdaters
. The traitStateVarInterface
defined methods used by core to solicit what data a state var needed, and to trigger it to recompute its data.Updaters
is more descriptive thanInterface
.The word
Interface
has been removed from theGeneral*StateVar
structs. It didn't seem to be adding anything.General*StateVar
structs were renamed*StateVar
structs and put in ageneral_state_var
module.StateVarReadOnlyView
->StateVarView
. Rust convention is that everything is immutable by default and mutable things are distinguished by special words. In general aview
should be considered immutable, so we can use the shorter name.