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
Currently, we don't support primitive types in the state tree. The reason is that it's so very convenient to assume that these three things are all the same:
The type of the constructor parameter
The type returned by the getter
The type returned by Reference.value()
Aside from primitives, these are always the same. For primitives, there's no way to make a Reference<int> whose value() method returns int.
This leaves us with two alternatives:
First, we could use Reference<Integer> for fields of type int. We'd need to beef up a bunch of Bosk, BoskDriver, and PathCompiler logic to become aware that the Reference.targetType() and the return type of Reference.value() could be different.
Pros
Only one kind of Reference
Cons
Boxing and unboxing required, which can harm performance
Complexity of having Reference.value() return a type different from that of the field
Second, we could introduce some primitive reference types, like IntReference.
Pros
No boxing/unboxing, so efficient
Reference.value() returns the exact same type as that of the field
Cons
Multiple Reference types that need to be supported everywhere, such as in the BoskDriver interface
Supporting separate primitive reference types may be infeasibly cumbersome, so we might be stuck with the first approach.
It's definitely possible to make this work. It just hasn't yet been worth the effort. It would affect Bson and Json serialization, as well as the PathCompiler: they would all need to add special boxing/unboxing cases for fields whose type (eg. int) does not match the type parameter of the Reference (eg. Integer).
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, we don't support primitive types in the state tree. The reason is that it's so very convenient to assume that these three things are all the same:
Reference.value()Aside from primitives, these are always the same. For primitives, there's no way to make a
Reference<int>whosevalue()method returnsint.This leaves us with two alternatives:
First, we could use
Reference<Integer>for fields of typeint. We'd need to beef up a bunch ofBosk,BoskDriver, andPathCompilerlogic to become aware that theReference.targetType()and the return type ofReference.value()could be different.ReferenceReference.value()return a type different from that of the fieldSecond, we could introduce some primitive reference types, like
IntReference.Reference.value()returns the exact same type as that of the fieldReferencetypes that need to be supported everywhere, such as in theBoskDriverinterfaceSupporting separate primitive reference types may be infeasibly cumbersome, so we might be stuck with the first approach.
It's definitely possible to make this work. It just hasn't yet been worth the effort. It would affect Bson and Json serialization, as well as the
PathCompiler: they would all need to add special boxing/unboxing cases for fields whose type (eg.int) does not match the type parameter of theReference(eg.Integer).Beta Was this translation helpful? Give feedback.
All reactions