You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ViewModel or Store such as having the state and as a reference type, That should be compared with pointer-personality, not comparing the state.
Because they are always stateful.
If we do compare with the state structure and data inside, the program might run the wrong way.
So I recommend the developer using a template abstract class to create ViewModel.
/**
An object as a base class to create an object that provides equatability and hash-value by the pointer personality.
*/
openclassStatefulObjectBase:Hashable{publicfinalclassfunc==(lhs:StatefulObjectBase, rhs:StatefulObjectBase)->Bool{
lhs === rhs
}publicfunc hash(into hasher:inoutHasher){
__identifier.hash(into:&hasher)}privatevar__identifier:ObjectIdentifier!publicinit(){self.__identifier =ObjectIdentifier(self)}}#if canImport(DifferenceKit)
import DifferenceKit
extensionStatefulObjectBase:Differentiable{publicvardifferenceIdentifier:ObjectIdentifier{self.__identifier
}}#endif
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
ViewModel or Store such as having the state and as a reference type, That should be compared with pointer-personality, not comparing the state.
Because they are always stateful.
It's like comparing UIView behavior.
If we do compare with the state structure and data inside, the program might run the wrong way.
So I recommend the developer using a template abstract class to create ViewModel.
Beta Was this translation helpful? Give feedback.
All reactions