Better docs about whether 'operator==' is necessary #568
Replies: 1 comment 1 reply
-
Hey 👋 (I realize this thread is a bit old). I'm not sure what your question is exactly, but I can address this bit of confusion here:
Remember that providers emit immutable values. If you have a Your classes could implement But yeah, not much documentation about it, it is briefly mentioned at the bottom of: https://riverpod.dev/docs/concepts/reading |
Beta Was this translation helpful? Give feedback.
-
As I was implementing reacting to partial state changes (see #564), I wrote a provider like this:
and it all worked, i.e. my UI is rebuilt only the the
status
field changes. Nice, but at the same time, I was surprised (partially because it is so darn easy) - because I didn't have to do anything special, no filtering on my own. It turns out all of this is becauseoperator==
is involved, andstatus
being anenum
gets it for free.I got back to the docs and couldn't find details anywhere, the next best thing is this sentence on
watch
:But it isn't documented anywhere what
a new value
is, apparently it is something that returnsfalse
fromoperator==
, but it is not explained, so it could be a new reference (to an otherwise structurally identical object). At the same time, it is explicitly stated thatfamily
parameters must implementoperator==
.On the same note, I'm also using
StateNotifier
and as far as I know it also doesn't state what is required for a state change to be discovered. The next best thing isdocumented on the
state
property, but it fails to explain what 'updating' really means - just setting the property (even if the same reference), or setting it to a new reference, or setting to something that returnsfalse
foroperator==
(seriously, I don't even know the answer to this question, I will need to go back to my code and experiment).(EDIT: in
StateNotifier
, it seems like setting thestate
property to anything, even the same reference, triggers a notification. This makes it pretty confusing asStateNotifier.state
and states returned byProvider
are on the opposite spectrum - set to anything, even the same reference vs set to something whereoperator==
==false
)The answers to these questions may be obvious to someone with experience with
StateNotifier
andRiverpod
, but maybe it is worth considering being very, very explicit in the documentation?Beta Was this translation helpful? Give feedback.
All reactions