Struct SelectorScope Copy item path Source pub struct SelectorScope<Lens> { }Expand description SelectorScope is the primitive that backs the store system.
Under the hood stores consist of two different parts:
The underlying lock that contains the data in the store.
A tree of subscriptions used to make the store reactive.
The SelectorScope contains a view into the lock (Lens) and a path into the subscription tree. When
the selector is read to, it will track the current path in the subscription tree. When it it written to
it marks itself and all its children as dirty.
When you derive the Store macro on your data structure,
it generates methods that map the lock to a new type and scope the path to a specific part of the subscription structure.
For example, a Counter store might look like this:
ⓘ #[derive(Store)]
struct Counter {
count: i32,
}
impl CounterStoreExt for Store<Counter> {
fn count(
self ,
) -> dioxus_stores::Store<
i32,
dioxus_stores::macro_helpers::dioxus_signals::MappedMutSignal<i32, __W>,
> {
let __map_field: fn (& CounterTree) -> & i32 = |value| & value.count;
let __map_mut_field: fn (&mut CounterTree) -> &mut i32 = |value| &mut value.count;
let scope = self .selector().scope(0u32 , __map_field, __map_mut_field);
dioxus_stores::Store::new(scope)
}
}
The count method maps the lock to the i32 type and creates a child 0 path in the subscription tree. Only writes
to that 0 path or its parents will trigger a re-render of the components that read the count field.
Create a child selector scope for a hash key. The scope will only be marked as dirty when a
write occurs to that key or its parents.
Note the hash is lossy, so there may rarely be collisions. If a collision does occur, it may
cause reruns in a part of the app that has not changed. As long as derived data is pure,
this should not cause issues.
Create a child selector scope for a specific index. The scope will only be marked as dirty when a
write occurs to that index or its parents.
Create a hashed child selector scope for a specific index without mapping the writer. The scope will only
be marked as dirty when a write occurs to that index or its parents.
Create a child selector scope for a specific index without mapping the writer. The scope will only
be marked as dirty when a write occurs to that index or its parents.
Map the view into the writable data without creating a child selector scope
Track this scope shallowly.
Track this scope recursively.
Mark this scope as dirty recursively.
Mark this scope as dirty shallowly.
Mark this scope as dirty at and after the given index.
Map the writer to a new type.
Write without notifying subscribers.
Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
Read more Converts to this type from the input type.
Tests for self and other values to be equal, and is used by ==.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
The target type of the reference.
The type of the storage this readable uses.
Try to get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal.
Read more Try to peek the current value of the signal without subscribing to updates. If the value has
been dropped, this will return an error.
Read more Get the underlying subscriber list for this readable. This is used to track when the value changes and notify subscribers.
Additional data associated with the write reference.
Try to get a mutable reference to the value without checking the lifetime. This will update any subscribers.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Create an instance of this type from an initialization function
Instruments this type with the provided
Span, returning an
Instrumented wrapper.
Read more Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
Box the readable value into a trait object. This is useful for passing around readable values without knowing their concrete type.
Get the current value of the state. If this is a signal, this will subscribe the current scope to the signal.
If the value has been dropped, this will panic. Calling this on a Signal is the same as
using the signal() syntax to read and subscribe to its value
Try to get the current value of the state. If this is a signal, this will subscribe the current scope to the signal.
Get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal.
Read more Get the current value of the state without subscribing to updates. If the value has been dropped, this will panic.
Read more Try to peek the current value of the signal without subscribing to updates. If the value has
been dropped, this will return an error.
Get the current value of the signal without checking the lifetime.
Unlike read, this will not subscribe the current scope to the signal which can cause parts of your UI to not update. Read more Map the references of the readable value to a new type. This lets you provide a view
into the readable value without creating a new signal or cloning the value.
Read more Clone the inner value and return it. If the value has been dropped, this will panic.
Run a function with a reference to the value. If the value has been dropped, this will panic.
Run a function with a reference to the value. If the value has been dropped, this will panic.
Index into the inner value and return a reference to the result. If the value has been dropped or the index is invalid, this will panic.
Check if the hashmap is empty.
Get the length of the hashmap.
Get the capacity of the hashmap.
Get the value for the given key.
Check if the hashmap contains the given key.
Check if the hashset is empty.
Get the length of the hashset.
Get the capacity of the hashset.
Check if the hashset contains the given value.
Unwraps the inner value and clones it.
Attempts to read the inner value of the Option.
Unwraps the inner value and clones it.
Attempts to read the inner value of the Option.
Check the capacity of the string.
Returns the length of the inner vector.
Returns true if the inner vector is empty.
Get the first element of the inner vector.
Get the last element of the inner vector.
Get the element at the given index of the inner vector.
Get an iterator over the values of the inner vector.
Spawn the value into the dioxus runtime if it is an async block
Convert from a type to another type.
Convert from a type to another type.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Box the writable value into a trait object. This is useful for passing around writable values without knowing their concrete type.
Get a mutable reference to the value. If the value has been dropped, this will panic.
Try to get a mutable reference to the value.
Get a mutable reference to the value without checking the lifetime. This will update any subscribers.
Read more Map the references and mutable references of the writable value to a new type. This lets you provide a view
into the writable value without creating a new signal or cloning the value.
Read more Run a function with a mutable reference to the value. If the value has been dropped, this will panic.
Set the value of the signal. This will trigger an update on all subscribers.
Invert the boolean value of the signal. This will trigger an update on all subscribers.
Index into the inner value and return a reference to the result.
Takes the value out of the Signal, leaving a Default in its place.
Replace the value in the Signal, returning the old value.
Clears the map, removing all key-value pairs.
Retains only the key-value pairs that match the given predicate.
Inserts a key-value pair into the map. If the key was already present, the old value is returned.
Extends the map with the key-value pairs from the given iterator.
Removes a key from the map, returning the value at the key if the key was previously in the map.
Get a mutable reference to the value at the given key.
Clear the hash set.
Retain only the elements specified by the predicate.
Inserts a value into the set. Returns true if the value was not already present.
Extends the set with the values from the given iterator.
Removes a value from the set. Returns true if the value was present.
Gets the value out of the Option, or inserts the given value if the Option is empty.
Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.
Attempts to write the inner value of the Option.
Pushes a character to the end of the string.
Pushes a character to the end of the string.
Pops a character from the end of the string.
Inserts a string at the given index.
Inserts a character at the given index.
Remove a character at the given index
Replace a range of the string with the given string.
Clears the string, removing all characters.
Extends the string with the given iterator of characters.
Truncates the string to the given length.
Splits the string off at the given index, returning the tail as a new string.
Pushes a new value to the end of the vector.
Pops the last value from the vector.
Inserts a new value at the given index.
Removes the value at the given index.
Clears the vector, removing all values.
Extends the vector with the given iterator.
Truncates the vector to the given length.
Swaps two values in the vector.
Retains only the values that match the given predicate.
Splits the vector into two at the given index.
Try to mutably get an element from the vector.
Gets an iterator over the values of the vector.