sgrekov / AndroidMobiusSample

A sample how to use Mobius Unidirectional Dataflow library in Android App
1 stars 0 forks source link

Remove custom `next` method? #2

Closed togi closed 6 years ago

togi commented 6 years ago

Normally we would use Effects.effects() to do the same thing, for example:

// only effects
dispatch(effects(PlaySoundEffect))

// model and effects
next(model.copy(flag=true), effects(DoSomeEffect))
sgrekov commented 6 years ago

Agree, but In my experience most of the return cases from update function is "newState, Effect", hence to write all the time Next.next(model.copy(..), setOf(Effect)) or Next.next(model.copy(..), effects(Effect)) is tedious. Maybe implement another helper method in Next class?

togi commented 6 years ago

That's true, the most common case is a single effect. The thing is, we've tried countless different variations of the next API and unfortunately most of the variants you can have become quite difficult to use in practice, as they cause type inference problems in Java. You can see some of the traces of this in the unit tests of mobius.

It's possible we could do better in some kotlin-specific helpers, so maybe there will be a mobius-kotlin library in the future. Either way I mostly wanted to let you know that right now we use next(newModel, effects(SomeEffect)) ourselves. It's a bit more verbose yes, but at the same time it reads quite easily.

sgrekov commented 6 years ago

I got your point - this is more ideomatic way of writing update function, will fix that.