Is there a good practice for using Signal? #2263
Replies: 1 comment
-
yeah, had the same struggles few days ago when comming new to dioxus and reading the actual docs. for a start.. this is my conclusion of alternative ways to use signals count += 1;
*count.write() = 1;
*count.write() += 1;
*count.write() = *count.read() + 1;
*count.write() = count() + 1;
*count.write() = count.cloned() + 1;
*count.write() = count.read().clone() + 1;
// every signal has .set(value) method, that calls `*self.write() = value` inside
count.set(1);
calling types as functions dioxus/packages/signals/src/read.rs Line 119 in ffe02b4 |
Beta Was this translation helpful? Give feedback.
-
I'm new about Dioxus for two days and started directly from 0.5.
When I read the document(just the guide and a piece of reference), the part about signal was really confusing.
signal
,signal =
,signal()
,*signal.read()
,signal.read().clone()
,signal.write()
,*signal.write() =
,signal().write().push()
,signal.push()
, ..., there are too many ways to use it.The documentation doesn’t make it very clear, and the code examples also use them mixedly.
I think the key is about signal is
Copy
or not, but still confused in using.So, is there some good practice for using signal?
I watching into the source and docs.rs, and find that
signal()
is just like thesignal.read().clone()
, but does this two way the same? Eveytime I call signal(), it cloned?the
signal.set(value)
is calling*signal.write() = value
. Actually, theset()
is in doc'sMigration
anddynamic rendering
chapter, but I find it in docs.rs firstly🤣. It seemsset()
is exist in before verson. I think this should be in theGuide
and clearly explained.And there are
Vec
andOption
signal methods in docs.rs doc. BUT this seems not in doc(maybe I don't find?)Anyway, the doc is not frendly enough for me😢.
Beta Was this translation helpful? Give feedback.
All reactions