Closed grepsuzette closed 2 years ago
After I posted this, I tried to remove the type in the constructor of one of my classes (been struggling for weeks, there were like 4 rewrites) and suddenly all the app works and updates magically!
The build macro for Model working around the constructor maybe has a bug? (I hope it's a bug and not a type issue)
Yeah, this one is a bit tricky.
The problem here is that @:external
consumes a coconut.data.Value
which is essentially an Observable
with a @:from macro
cast that will wrap non-observable expressions in Observable.auto(() -> $expr)
.
If you remove the type hint, then season
is inferred to Value<Option<Season>>
(which is the correct type to use here).
Thus var prov1 = new FruitsProvider(world.season);
compiles to var prov1 = new FruitsProvider(Observable.auto(() -> world.season));
.
If you leave the type as it is, then you get var prov1 = new FruitsProvider(world.season);
and that only passes the current value to the FruitsProvider
and its constructor implementation will be generated with this = { season: Observable.auto(() -> season) }
- observing a function argument does not cause updates.
Sorry for the trouble. The upcoming v1 will axe this footgun: https://github.com/MVCoconut/coconut.data/issues/77
Weird thing here:
If constructor of FruitsProvider is kept as in the example, the name of the season will never show up ("unknown yet"):
public function new(season:Option<Season>) this = { season:season }
But it will work if either:
public function new(season) this = { season:season }
new FruitsProvider({season:"winter"}))
)