Revert "feat: make localsignal id relative to its props"

This reverts commit 9458d95222.
This commit is contained in:
Byson94
2025-10-30 15:11:00 +05:30
parent f5ad63ed33
commit 9c15f8aed1
3 changed files with 16 additions and 21 deletions

View File

@@ -227,14 +227,6 @@ pub fn hash_props_and_type(props: &Map, widget_type_str: &str) -> u64 {
hasher.finish()
}
pub fn hash_props(props: &Map) -> u64 {
let mut hasher = AHasher::default();
props.hash(&mut hasher);
hasher.finish()
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -1,10 +1,17 @@
use crate::ast::{WidgetNode, hash_props};
use crate::ast::WidgetNode;
use crate::updates::{LocalSignal, LocalDataBinder, register_signal};
use rhai::{Array, Engine, EvalAltResult, Map, NativeCallContext};
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
fn unique_id() -> u64 {
NEXT_ID.fetch_add(1, Ordering::Relaxed)
}
/// Converts a Dynamic array into a Vec<WidgetNode>, returning proper errors with position.
fn children_to_vec(
children: Array,
@@ -81,7 +88,7 @@ pub fn register_all_widgets(engine: &mut Engine, all_nodes: &Rc<RefCell<Vec<Widg
// == Special signal
engine.register_fn("localsignal", |props: Map| -> Result<LocalSignal, Box<EvalAltResult>> {
let id = hash_props(&props);
let id = unique_id();
let signal = LocalSignal {
id,
props,

View File

@@ -94,18 +94,14 @@ thread_local! {
}
pub fn register_signal(id: u64, signal: Rc<LocalSignal>) {
LOCAL_SIGNALS.with(|registry| {
let mut map = registry.borrow_mut();
if !map.contains_key(&id) {
if let Some(initial_dyn) = signal.props.get("initial") {
if let Some(initial_str) = initial_dyn.clone().try_cast::<String>() {
signal.data.set_value(&initial_str);
}
}
map.insert(id, signal.clone());
if let Some(initial_dyn) = signal.props.get("initial") {
if let Some(initial_str) = initial_dyn.clone().try_cast::<String>() {
signal.data.set_value(&initial_str);
}
}
LOCAL_SIGNALS.with(|registry| {
registry.borrow_mut().insert(id, signal.clone());
});
}