Hotreloading of for/if/body, formatted strings, literals, component props, nested rsx, light CLI rewrite, cli TUI (#2258)
Hotreload the contents of for loops, if chains, component bodies, props, attributes, and any literals discovered in rsx! Add a TUI renderer to the CLI. Improve the CLI build system to be async and parallel. Refactor RSX to allow partial expansion of expressions. Merge autofmt implementations for consistency. Merge the representation of elements and components under the hood. Add a diagnostics system for rsx for improved error messages. Drop interprocess and move to websockets for communication between the CLI and the server. Assign IDs to nodes and attributes in a stable way to be used in non compiler contexts. Add hotreloading to any body of component/for loop/if chain/etc. --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com> Co-authored-by: Liam Mitchell <liamkarlmitchell@gmail.com>
This commit is contained in:
181 files changed
+12755
-10806
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use crate::write::Writable;
|
||||
use crate::{read::Readable, ReadableRef};
|
||||
use crate::{write::Writable, GlobalKey};
|
||||
use crate::{WritableRef, Write};
|
||||
use dioxus_core::prelude::ScopeId;
|
||||
use dioxus_core::{prelude::ScopeId, Runtime};
|
||||
use generational_box::UnsyncStorage;
|
||||
use std::ops::Deref;
|
||||
|
||||
@@ -12,18 +12,40 @@ use crate::Signal;
|
||||
/// A signal that can be accessed from anywhere in the application and created in a static
|
||||
pub struct GlobalSignal<T> {
|
||||
initializer: fn() -> T,
|
||||
key: GlobalKey<'static>,
|
||||
}
|
||||
|
||||
impl<T: 'static> GlobalSignal<T> {
|
||||
/// Create a new global signal with the given initializer.
|
||||
#[track_caller]
|
||||
pub const fn new(initializer: fn() -> T) -> GlobalSignal<T> {
|
||||
GlobalSignal { initializer }
|
||||
let key = std::panic::Location::caller();
|
||||
GlobalSignal {
|
||||
initializer,
|
||||
key: GlobalKey::new(key),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the signal that backs this global.
|
||||
/// Get the key for this global
|
||||
pub fn key(&self) -> GlobalKey<'static> {
|
||||
self.key.clone()
|
||||
}
|
||||
|
||||
/// Create this global signal with a specific key.
|
||||
/// This is useful for ensuring that the signal is unique across the application and accessible from
|
||||
/// outside the application too.
|
||||
pub const fn with_key(initializer: fn() -> T, key: &'static str) -> GlobalSignal<T> {
|
||||
GlobalSignal {
|
||||
initializer,
|
||||
key: GlobalKey::new_from_str(key),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the signal that backs this .
|
||||
pub fn signal(&self) -> Signal<T> {
|
||||
let key = self as *const _ as *const ();
|
||||
let key = self.key();
|
||||
let context = get_global_context();
|
||||
|
||||
let read = context.signal.borrow();
|
||||
|
||||
match read.get(&key) {
|
||||
@@ -44,6 +66,15 @@ impl<T: 'static> GlobalSignal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn maybe_with_rt<O>(&self, f: impl FnOnce(&T) -> O) -> O {
|
||||
if Runtime::current().is_none() {
|
||||
f(&(self.initializer)())
|
||||
} else {
|
||||
self.with(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Write this value
|
||||
pub fn write(&self) -> Write<'static, T, UnsyncStorage> {
|
||||
self.signal().try_write_unchecked().unwrap()
|
||||
|
||||
Reference in new issue
Block a user