adeo-opensource / kviewmodel--mpp

Library to sharing view model
Apache License 2.0
48 stars 4 forks source link

Add sync baseStore #23

Open evgenru opened 1 year ago

evgenru commented 1 year ago

Adds synchronous event handling. This helps to avoid inconsistent data when 2 events arrive at the same time. This makes the store part of functional programming.

To implement your store, you need:

  1. declare your events and states
  2. override the behavior of the reduce method, which acts as a function: newState = f ( event, oldState )
Skeptick commented 1 year ago

Hello. Thanks for PR. This is a rather unusual problem when events come from different threads and there is a need for them to be processed synchronously. In my practice this was not necessary. In general, it's recommended to design viewmodel so that events do not depend on each other and there is no need for sequential processing.

I don't think it should be part of the library. You can always inherit from BaseSharedViewModel and add the desired implementation of obtainEvent