{"id":17990290,"url":"https://github.com/sgrekov/teapot","last_synced_at":"2025-03-25T23:31:18.637Z","repository":{"id":50217354,"uuid":"144774391","full_name":"sgrekov/Teapot","owner":"sgrekov","description":"Unidirectional Dataflow library for Android inspired by The Elm Architecture","archived":false,"fork":false,"pushed_at":"2021-06-01T19:09:20.000Z","size":372,"stargazers_count":30,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-20T22:23:22.863Z","etag":null,"topics":["android","architecture","elm-architecture","state-management","unidirectional-data-flow"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgrekov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-14T21:34:36.000Z","updated_at":"2024-01-18T03:21:44.000Z","dependencies_parsed_at":"2022-09-26T20:52:40.365Z","dependency_job_id":null,"html_url":"https://github.com/sgrekov/Teapot","commit_stats":null,"previous_names":["factorymarketretailgmbh/rxelm"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgrekov%2FTeapot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgrekov%2FTeapot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgrekov%2FTeapot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgrekov%2FTeapot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgrekov","download_url":"https://codeload.github.com/sgrekov/Teapot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245561506,"owners_count":20635755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","architecture","elm-architecture","state-management","unidirectional-data-flow"],"created_at":"2024-10-29T19:17:21.109Z","updated_at":"2025-03-25T23:31:13.585Z","avatar_url":"https://github.com/sgrekov.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Bintray](https://img.shields.io/badge/Bintray-0.9.1-green.svg)](https://bintray.com/sgrekov/Teapot/Teapot/0.9.1)\n[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/FactoryMarketRetailGmbH/RxElm/blob/master/LICENSE)\n\n# Teapot\nUnidirectional Dataflow library for Android inspired by The Elm Architecture. \n\n\n## Dependency\n\n\n```\nrepositories {\n    ...\n    mavenCentral()\n    ...\n}\n\nimplementation 'dev.teapot:teapot:0.9.1'\ntestImplementation 'dev.teapot:teapottest:0.9.1'\n```\n\n\n\n## Concepts \nTeapot is heavily influenced by The Elm Architecture(TEA). Its core concepts:\n\n* Unidirectional dataflow\n* Immutable state\n* Managed side effects\n\nIt allows to write highly testable and predictable UI logic. Teapot is written in Kotlin and supports executing side effects via RxJava2 or Coroutines.\n\n### Core types\n#### State \nThis is the type for describing the state of your app or screen. \n\n#### Msg   \nBase type for all events happening during interaction with UI (such as button click, text inputs, etc)\n\n#### Cmd  \nType for side-effects. If you create Cmd, that means you want to execute a particular side effect (http request or other IO operation).\nWhen executed, the command will return new Msg with resulting data.\n\n#### Update()  \nFunction 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. \nThe main aspect of this function is that it is a pure function. That means there must be no side effects inside this function.\n\n#### Render() \nFunction render() takes State as an input, and renders view in declarative manner. \n\n## Getting Started\n\n### Minimal implementation\n\n```kotlin\n\ndata class IncrementDecrementState(val value: Int = 0) : State()\n    \nobject Inc : Msg()\nobject Dec : Msg()    \n    \nclass MyFragment : Fragment(), Upd\u003cIncrementDecrementState\u003e, Renderable\u003cIncrementDecrementState\u003e {\n\n  \n    private lateinit var plusBtn: Button\n    private lateinit var minusBtn: Button\n    private lateinit var counterText: TextView   \n                    \n    val program = ProgramBuilder()\n                        .outputScheduler(AndroidSchedulers.mainThread())\n                        .build(this)            \n   \n\n    override fun onCreateView(\n            inflater: LayoutInflater, container: ViewGroup?,\n            savedInstanceState: Bundle?\n        ): View? {\n        \n        val view = inflater.inflate(R.layout.main_layout, container, false)       \n                        \n        plusBtn = view.findViewById(R.id.plus_btn)\n        minusBtn = view.findViewById(R.id.minus_btn)\n        counterText = view.findViewById(R.id.counter_text)\n               \n        program.run(initialState = IncrementDecrementState(value = savedInstanceState?.getInt(\"counter\", 0) ?: 0))              \n    }\n    \n    override fun update(msg: Msg, state: counterText): Update\u003cIncrementDecrementState\u003e {          \n            return when (msg) {            \n                is Inc -\u003e Update.state(state.copy(value = state.value + 1))               \n                is Dec -\u003e Update.state(state.copy(value = state.value - 1))\n                else -\u003e Update.idle()\n            }\n    }\n    \n    override fun render(state: IncrementDecrementState) {\n        state.apply {\n            counterText.setText(value)\n        }\n    }\n    \n    override fun onSaveInstanceState(outState  : Bundle) {\n      super.onSaveInstanceState(outState)\n     \n      outState.putString(\"counter\", program.state().value)\n    }\n    \n    @Override\n    fun onDestroyView() {\n      super.onDestroyView()\n      program.stop()\n    }\n    \n}\n```\n\n### Sample Project \nTo see full working sample, check out [the sample app](https://github.com/sgrekov/Teapot/tree/master/sample) \n\n\n### Resources\n* Taming state in Android with Elm Architecture and Kotlin [series of blog posts](https://proandroiddev.com/taming-state-in-android-with-elm-architecture-and-kotlin-part-1-566caae0f706)\n* [Official guide into The Elm Architecture](https://guide.elm-lang.org/architecture/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgrekov%2Fteapot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgrekov%2Fteapot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgrekov%2Fteapot/lists"}