Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Dec 19, 2024
1 parent 0197a6c commit e7bfd17
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

FlowMVI is a Kotlin Multiplatform architectural framework based on coroutines.
It enables you to extend your business logic with reusable plugins, handle errors,
achieve thread-safety, and more. It takes about 10 minutes and 50 lines of code to get started.
achieve thread-safety, and more. It takes about 10 minutes to get started.

## ⚡️ Quickstart:

Expand Down Expand Up @@ -90,6 +90,8 @@ Instead, this library focuses on building a supporting infrastructure to enable
Here's what you get:

* Powerful Plug-In system to automate processes and **reuse any business logic** you desire
* Create automatic analytics handlers, websocket connections, error handling mechanisms, or anything else **once**
and reuse them throughout your whole project automatically
* Automatically **recover from any errors** and report them to analytics.
* Build fully **async, reactive and parallel apps** - with no manual thread synchronization required!
* Create **multiplatform business logic** components with pluggable UI
Expand All @@ -112,16 +114,19 @@ Here's what you get:
* **Test any business logic** using clean, declarative DSL.
* Learn more by exploring the [sample app](https://opensource.respawn.pro/FlowMVI/sample/) in your browser

## 👀 What does it look like?
## 👀 How to get started?

To get started, all you have to do is:
All you have to do is:

### 1. Define a Contract:

```kotlin
data class State(
val counter: Int = 0,
) : MVIState
sealed interface State : MVIState {
data object Loading : State
data class Error(val e: Exception) : State
data class Content(val counter: Int = 0) : State
}


sealed interface Intent : MVIIntent {
data object ClickedCounter : Intent
Expand All @@ -135,11 +140,28 @@ sealed interface Action : MVIAction {
### 2. Declare your business logic:

```kotlin
val counterStore = store(initial = State(), scope = coroutineScope) {

val counterStore = store(initial = State.Loading, scope = coroutineScope) {

// install plugins you need
install(analyticsPlugin)

// recover from errors
recover { e: Exception ->
updateState { State.Error(e) }
null
}

// load data
init {
updateState {
State.Content(counter = repository.loadCounter())
}
}

// respond to events
reduce { intent: Intent ->
when (intent) {
is ClickedCounter -> updateState {
is ClickedCounter -> updateState<State.Content, _> {
action(ShowMessage("Incremented!"))

copy(counter = counter + 1)
Expand All @@ -151,14 +173,13 @@ val counterStore = store(initial = State(), scope = coroutineScope) {
store.intent(ClickedCounter)
```

That's it!

> But my app is really complex! I want state persistence, error-handling, analytics, threading etc...
### 3. Scale your app

No problem, your logic's complexity now scales **linearly**. Adding a new feature is as simple as calling a function.
With FlowMVI, complexity **does not grow** no matter how many features you add.
Adding a new feature is as simple as calling a function.

<details>
<summary>Example advanced configuration</summary>
<summary>Advanced configuration example</summary>

```kotlin
class CounterContainer(
Expand Down Expand Up @@ -202,12 +223,6 @@ class CounterContainer(
repo.startTimer()
}

// handle any errors
recover { e: Exception ->
action(ShowMessage(e.message))
null
}

// save resources when there are no subscribers
whileSubscribed {
repo.timer.collect {
Expand Down Expand Up @@ -259,6 +274,12 @@ fun analyticsPlugin(analytics: Analytics) = plugin<MVIState, MVIIntent, MVIActio
onException { e ->
analytics.logError(e)
}
onSubscribe {
analytics.logEngagementStart()
}
onUnsubscribe {
analytics.logEngagementEnd()
}
onStop {
analytics.logScreenLeave()
}
Expand Down Expand Up @@ -367,10 +388,9 @@ timerPlugin(timer).test(Loading) {

## Debugger IDE Plugin + App

IDE plugin generates code and lets you debug and control your app remotely:
[![Plugin](https://img.shields.io/jetbrains/plugin/v/25766?style=flat)](https://plugins.jetbrains.com/plugin/25766-flowmvi)

IDE plugin generates features in 4 keystrokes and lets you debug and control your app remotely:

https://github.com/user-attachments/assets/05f8efdb-d125-4c4a-9bda-79875f22578f

## People love the library:
Expand All @@ -385,8 +405,7 @@ https://github.com/user-attachments/assets/05f8efdb-d125-4c4a-9bda-79875f22578f

## Ready to try?

It takes 10 minutes to get started. Begin by reading
the [Quickstart Guide](https://opensource.respawn.pro/FlowMVI/#/quickstart).
Begin by reading the [Quickstart Guide](https://opensource.respawn.pro/FlowMVI/#/quickstart).

----

Expand Down

0 comments on commit e7bfd17

Please sign in to comment.