All Projects β†’ sgrekov β†’ Teapot

sgrekov / Teapot

Licence: Apache-2.0 license
Unidirectional Dataflow library for Android inspired by The Elm Architecture

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Teapot

Unidirectional Architecture On Mobile
Dive into πŸ“± Unidirectional Architecture!
Stars: ✭ 115 (+296.55%)
Mutual labels:  elm-architecture, unidirectional-data-flow
NestedReact
BackboneJS compatibility layer for React-MVx MVVM framework.
Stars: ✭ 79 (+172.41%)
Mutual labels:  state-management, unidirectional-data-flow
Reactivereswift
Unidirectional Data Flow in Swift via FRP - Inspired by Elm
Stars: ✭ 133 (+358.62%)
Mutual labels:  elm-architecture, unidirectional-data-flow
Reactor
πŸ”„ Unidirectional data flow in Swift.
Stars: ✭ 174 (+500%)
Mutual labels:  elm-architecture, unidirectional-data-flow
Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+644.83%)
Mutual labels:  state-management, elm-architecture
Corerender
Moved to https://github.com/alexdrone/Render
Stars: ✭ 25 (-13.79%)
Mutual labels:  elm-architecture, unidirectional-data-flow
Render
UIKit a-lΓ  SwiftUI.framework [min deployment target iOS10]
Stars: ✭ 2,150 (+7313.79%)
Mutual labels:  elm-architecture, unidirectional-data-flow
Keemun
No description or website provided.
Stars: ✭ 13 (-55.17%)
Mutual labels:  elm-architecture, unidirectional-data-flow
Rxstate
Redux implementation in Swift using RxSwift
Stars: ✭ 142 (+389.66%)
Mutual labels:  state-management, unidirectional-data-flow
Roxie
Lightweight Android library for building reactive apps.
Stars: ✭ 441 (+1420.69%)
Mutual labels:  state-management, unidirectional-data-flow
alveron-old
Opinionated Elm-inspired Redux Component Architecture for React
Stars: ✭ 17 (-41.38%)
Mutual labels:  state-management, elm-architecture
trux
Unidirectional data layer for reactive user interfaces
Stars: ✭ 59 (+103.45%)
Mutual labels:  state-management, unidirectional-data-flow
UniTEA
Implementation of The Elm Architecture for Unity3D
Stars: ✭ 31 (+6.9%)
Mutual labels:  state-management, elm-architecture
Elmdroid
Minimalistic Android implementation of The Elm Architecture with android architecture components integration.
Stars: ✭ 25 (-13.79%)
Mutual labels:  elm-architecture, unidirectional-data-flow
xstate.dart
xstate for dart & flutter
Stars: ✭ 31 (+6.9%)
Mutual labels:  state-management
lamp-luwak
Service-oriented state management for React
Stars: ✭ 12 (-58.62%)
Mutual labels:  state-management
space-state
Demo app for Subjecting State to Good Behavior
Stars: ✭ 46 (+58.62%)
Mutual labels:  state-management
temperjs
State management for React, made simple.
Stars: ✭ 15 (-48.28%)
Mutual labels:  state-management
react-without-redux
React State Management without Redux
Stars: ✭ 33 (+13.79%)
Mutual labels:  state-management
vuex-dry
[NO LONGER MAINTAINED] `vuex-dry` helps keep your vuex codes DRY.
Stars: ✭ 55 (+89.66%)
Mutual labels:  state-management

Bintray License

Teapot

Unidirectional Dataflow library for Android inspired by The Elm Architecture.

Dependency

repositories {
    ...
    mavenCentral()
    ...
}

implementation 'dev.teapot:teapot:0.9.1'
testImplementation 'dev.teapot:teapottest:0.9.1'

Concepts

Teapot is heavily influenced by The Elm Architecture(TEA). Its core concepts:

  • Unidirectional dataflow
  • Immutable state
  • Managed side effects

It allows to write highly testable and predictable UI logic. Teapot is written in Kotlin and supports executing side effects via RxJava2 or Coroutines.

Core types

State

This is the type for describing the state of your app or screen.

Msg β€Š

Base type for all events happening during interaction with UI (such as button click, text inputs, etc)

Cmd β€Š

Type for side-effects. If you create Cmd, that means you want to execute a particular side effect (http request or other IO operation). When executed, the command will return new Msg with resulting data.

Update() β€Š

Function Update takes Msg and State as input, and returns a pair of two valuesβ€Šβ€”β€Šnew State and Cmd, or simply speaking, what side effect you want to execute for incoming Msg. The main aspect of this function is that it is a pure function. That means there must be no side effects inside this function.

Render()

Function render() takes State as an input, and renders view in declarative manner.

Getting Started

Minimal implementation

data class IncrementDecrementState(val value: Int = 0) : State()
    
object Inc : Msg()
object Dec : Msg()    
    
class MyFragment : Fragment(), Upd<IncrementDecrementState>, Renderable<IncrementDecrementState> {

  
    private lateinit var plusBtn: Button
    private lateinit var minusBtn: Button
    private lateinit var counterText: TextView   
                    
    val program = ProgramBuilder()
                        .outputScheduler(AndroidSchedulers.mainThread())
                        .build(this)            
   

    override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? {
        
        val view = inflater.inflate(R.layout.main_layout, container, false)       
                        
        plusBtn = view.findViewById(R.id.plus_btn)
        minusBtn = view.findViewById(R.id.minus_btn)
        counterText = view.findViewById(R.id.counter_text)
               
        program.run(initialState = IncrementDecrementState(value = savedInstanceState?.getInt("counter", 0) ?: 0))              
    }
    
    override fun update(msg: Msg, state: counterText): Update<IncrementDecrementState> {          
            return when (msg) {            
                is Inc -> Update.state(state.copy(value = state.value + 1))               
                is Dec -> Update.state(state.copy(value = state.value - 1))
                else -> Update.idle()
            }
    }
    
    override fun render(state: IncrementDecrementState) {
        state.apply {
            counterText.setText(value)
        }
    }
    
    override fun onSaveInstanceState(outState  : Bundle) {
      super.onSaveInstanceState(outState)
     
      outState.putString("counter", program.state().value)
    }
    
    @Override
    fun onDestroyView() {
      super.onDestroyView()
      program.stop()
    }
    
}

Sample Project

To see full working sample, check out the sample app

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].