Kombucha UDF is a UDF library based on The Elm Architecture (TEA) concepts that helps to focus on logic of you application, rather than understanding what is going on.
- If you use android project, in your module build.gradle(.kts)
dependencies { // Core dependency for main functionality implementation("io.github.ikarenkov:kombucha-core:${version}") // For convinien mapping ui and preserving loosing ui effects implementation("io.github.ikarenkov:kombucha-ui-adapter:${version}") // For testing testImplementation("io.github.ikarenkov:kombucha-test:${version}") }
- If you use kotlin multiplatform project
kotlin { sourceSets { commonMain.dependencies { // Core dependency for main functionality implementation("io.github.ikarenkov:kombucha-core:${version}") // For convinien mapping ui and preserving loosing ui effects implementation("io.github.ikarenkov:kombucha-ui-adapter:${version}") } commonTest.dependencies { // For testing testImplementation("io.github.ikarenkov:kombucha-test:${version}") } } }
Take a look at CounterFeature for simple counter store implementation.
To create you store you need:
- Create an object named ${YourFeatureName}Feature and define your
Msg
,State
andEff
inside. - Create reducer, that implements your business logic. Take a look to the counterDslReducerReducer
- Create
EffectHandler
for side effects and unstable behavior. CounterEffectHandle - Create a store named ${YourFeatureName}Store and inherited
from Store, defining initial state, using
created
counterDslReducerReducer
andCounterEffectHandler
.
// to send a message
store.accept(Msg.OnIncreaseClick)
// to observe states
store.state.collect { ... }
// to observe effectts
store.effects.collect { ... }
There are 3 kotlin multiplatform libraries available for jvm, ios and js. Check out modules README.md for detailed description.
- kombucha-core - core library that contains main logic, such as store, reducer, effectHandler and so on.
- kombucha-ui-adapter - extension of library that helps to adapt your store for UI.
- kombucha-test - helper classes and functions that provides convenient dsl for tenting your store.
Store maintains the application's state and orchestrates the interactions between components. Basicly, Store is a base UDF components to interact, that holds state and can accept some messages to handle. It has one input and two outputs:
![](https://private-user-images.githubusercontent.com/17216532/300452849-09fff09b-f7f9-42c9-ab73-ce3f2f25fb9a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2MTY5ODMsIm5iZiI6MTcyNDYxNjY4MywicGF0aCI6Ii8xNzIxNjUzMi8zMDA0NTI4NDktMDlmZmYwOWItZjdmOS00MmM5LWFiNzMtY2UzZjJmMjVmYjlhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDIwMTEyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThhMDMxNmE0NmI4ODY5NzdmNjE0MTlkZWQwOThjMGMxNzdlN2FhOTM1NmVjYTg1N2ZkOWZiYTgwNGQ3ZjVjNTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rNCkvYzs4Bv3h4_V7xFgKkcnanZ5o-yCuTsNLeKhhwg)
Let's take a look to Store main components:
![](https://private-user-images.githubusercontent.com/17216532/300498642-9669c03c-2d9d-4610-a30a-58619a4bcfb7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2MTY5ODMsIm5iZiI6MTcyNDYxNjY4MywicGF0aCI6Ii8xNzIxNjUzMi8zMDA0OTg2NDItOTY2OWMwM2MtMmQ5ZC00NjEwLWEzMGEtNTg2MTlhNGJjZmI3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDIwMTEyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTRmNzcyNjJlZGQwMGVkMzJkODAxYzI1MDA0ZjVlOThiZDNjZDNjZTA3ZGY5OWZmNzQ3NjNlOGYzMGYwNTE3N2UmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.du8Xq1RrMGmT2DFbL9-UG56N1QWGk-ynewNn1lRSiMw)
- Reducer - pure function, generates a new state and produces effects that require handling.
- EffectHandler - receives effects from the reducer and has the ability to send messages back to trigger the reducer. Our way to comunicate with the outer world, including any operations that are not pure. F.e. requesting data from db or api or saving data, requesting random and e.t.c.
There are 3 main model: Msg, State, Eff. Msg - describes intention to do something. It can be user click, result from your back end or anything else. State - the state that is stored in store. It represents the state of your feature. Eff - describes side effects, that should be executed. It's just a description of your intention to something that is not a pure function. F.e. it can be request to load some data from backend, saving or reading data from database and e.t.c.
You can implement StoreFactory to customize creation of the store instead of using direct inheritance. It helps to implement dependency inversion principe. F.e. it can be used to implement exception logging