{"id":13756002,"url":"https://github.com/glung/elm-architecture-android","last_synced_at":"2025-05-10T03:30:34.469Z","repository":{"id":139581636,"uuid":"44479981","full_name":"glung/elm-architecture-android","owner":"glung","description":"An example of the ELM architecture on Android using Kotlin with Anko","archived":false,"fork":false,"pushed_at":"2016-10-05T19:04:50.000Z","size":71,"stargazers_count":59,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-16T11:33:28.410Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glung.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-10-18T13:55:15.000Z","updated_at":"2023-05-17T09:25:38.000Z","dependencies_parsed_at":"2024-01-05T22:01:01.934Z","dependency_job_id":null,"html_url":"https://github.com/glung/elm-architecture-android","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glung%2Felm-architecture-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glung%2Felm-architecture-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glung%2Felm-architecture-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glung%2Felm-architecture-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glung","download_url":"https://codeload.github.com/glung/elm-architecture-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253358069,"owners_count":21895967,"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":[],"created_at":"2024-08-03T11:00:34.021Z","updated_at":"2025-05-10T03:30:34.233Z","avatar_url":"https://github.com/glung.png","language":"Kotlin","funding_links":[],"categories":["Examples"],"sub_categories":["Other editors"],"readme":"# elm-architecture-android\n\nAn example of the [ELM architecture](https://github.com/evancz/elm-architecture-tutorial/) applied to Android using [Kotlin](kotlinlang.org) with [Anko](https://github.com/JetBrains/anko).\n\n# Activity\n\nThe [MainActivity](app/src/main/java/glung/elm_architecture/MainActivity.kt) defines a dispatch method (outside of its scope). \n\nThe `dispatch` method : \n- `update` the model\n- `render` a view for the updated model\n- `setContentView` with the view representing the updated model.\n\n`onCreate` the activity initialize the system with an `INIT` action and a new `Model`.  \n\n\n```\npublic class MainActivity : AppCompatActivity() {\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n\n        dispatch(this)\n    }\n\n}\n\nfun dispatch(activity: Activity, action: Action = Action.INIT, model: Model = Model()) {\n    val updatedModel = update(action, model)\n    val dispatch = dispatch(activity, updatedModel)\n\n    activity.setContentView(view(activity, updatedModel, dispatch))\n}\n\nfun dispatch(activity: Activity, model: Model) = { newAction: Action -\u003e\n    dispatch(activity, newAction, model)\n}\n\n```\n\n# The Counter\n\n\nAll the application logic is in [Counter.kt](app/src/main/java/glung/elm_architecture/counter.kt). \n\nThe file \n- declares the `Model`\n- declares the `Action`\n- implements the `update` function \n- implements the `view` function \n\n```\nsealed class Action {\n    object INIT : Action()\n\n    object UP : Action()\n\n    object DOWN : Action()\n}\n\ndata class Model(val counter: Int = 0)\n\nfun update(action: Action, model: Model): Model {\n    return when (action) {\n        is Action.INIT -\u003e Model()\n        is Action.UP -\u003e Model(model.counter + 1)\n        is Action.DOWN -\u003e Model(model.counter - 1)\n    }\n}\n\nfun view(context: Context, model: Model, dispatch : (Action) -\u003e Unit): LinearLayout {\n    with(context) {\n        return verticalLayout {\n            button(\"up\") {\n                onClick { dispatch(Action.UP) }\n            }\n            button(\"down\") {\n                onClick { dispatch(Action.DOWN) }\n            }\n            textView(model.counter.toString())\n        }\n    }\n}\n```\n\n# Note \n\nThis is experimental and made for a talk. Feedback welcomed.\n\n[@lungos](https://twitter.com/Lungos)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglung%2Felm-architecture-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglung%2Felm-architecture-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglung%2Felm-architecture-android/lists"}