1.0.0-alpha01: Safe state update and new API
Pre-release
Pre-release
What's Changed
There are a lot of changes in this release. It's currently experimental and the API may change further.
I've decided to implement a synchronous first-in-first-serve state update api, and because of that, all the APIs that exposed current state without properly handling the parallelism of updates were removed.
Breaking changes:
- Removed
currentState
. Use withState() instead. - Added withState() function that obtains a current state, then runs the given block while suspending every other client from accessing the state until that block is finished. This is done because by obtaining state and then mutating it, you inherently introduce race conditions to your code, and now the management of that is being done out of the box by the library. Previously, you had to keep track of those yourself
- State can now still be obtained and assigned as the
state
property, but these APIs are considered delicate and may be removed in the future if no use cases for them are found. - added new inline functions
updateState
andwithState
that work differently from thewithState
we were used to use.withState
now operates on a state, but does not change it, andupdateState
updates the state with the return value of its block. Proper contracts were implemented for them. - There are now new inline functions for updateState and withState that work the same as the previous
withState
function - if state does not match given type, the block isn't executed and state is not updated. reduce()
now has no return value. This is because users of the library don't always need to update the state. Often an intent reduction results just in an action or other processing being done.- removed
set(state)
from the api launchForState
is now calledlaunchRecovering
and does not require a state return value. It's now exposed via store and it's reducer scope- Introduced new typealiases for lambdas of
recover
andreduce
- The preferred way of creating and launching the store is
lazyStore()
(not launched) andlaunchedStore()
(created and launched on first access) MVIIntentScope
no longer implements CoroutineScope but rather has ascope
property- KMM migration plans are set in place. The library will get to the beta when the KMM migration is done for the core module.
- Tests are now fully passing. Code coverage is on its way.
Store.launch()
is nowStore.start()
MVIIntentScope
no longer implements MVIProvider to not let users abuse some functions like sending intents out of thereduce
block anymore.- All deps were updated to latest stable versions, namely kotlin (1.7.21) and compose (1.3.1 with compiler 1.4.0-alpha02)
Full Changelog: 0.2.6...1.0.0-alpha01