{"id":15059463,"url":"https://github.com/inamiy/reactiveautomaton","last_synced_at":"2025-10-04T18:31:42.556Z","repository":{"id":43129816,"uuid":"58230793","full_name":"inamiy/ReactiveAutomaton","owner":"inamiy","description":"🤖 ReactiveCocoa + State Machine, inspired by Redux and Elm.","archived":true,"fork":false,"pushed_at":"2021-12-12T05:05:45.000Z","size":300,"stargazers_count":207,"open_issues_count":0,"forks_count":6,"subscribers_count":7,"default_branch":"swift/5.0","last_synced_at":"2025-01-08T16:20:06.412Z","etag":null,"topics":["automaton","elm","reactivecocoa","redux","state-machine","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/inamiy.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":"2016-05-06T19:39:20.000Z","updated_at":"2024-03-04T04:48:30.000Z","dependencies_parsed_at":"2022-09-22T06:22:21.584Z","dependency_job_id":null,"html_url":"https://github.com/inamiy/ReactiveAutomaton","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FReactiveAutomaton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FReactiveAutomaton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FReactiveAutomaton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inamiy%2FReactiveAutomaton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inamiy","download_url":"https://codeload.github.com/inamiy/ReactiveAutomaton/tar.gz/refs/heads/swift/5.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235289311,"owners_count":18965921,"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":["automaton","elm","reactivecocoa","redux","state-machine","swift"],"created_at":"2024-09-24T22:44:08.403Z","updated_at":"2025-10-04T18:31:42.150Z","avatar_url":"https://github.com/inamiy.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"## NOTE: This repository has been discontinued in favor of [Actomaton](https://github.com/inamiy/Actomaton).\n\n# ReactiveAutomaton\n\n[ReactiveCocoa](https://github.com/ReactiveCocoa/ReactiveCocoa) + State Machine, inspired by [Redux](https://github.com/reactjs/redux) and [Elm](http://elm-lang.org/). A successor of [SwiftState](https://github.com/ReactKit/SwiftState).\n\n## Example\n\n(Demo app is available at [ReactiveCocoaCatalog](https://github.com/inamiy/ReactiveCocoaCatalog))\n\n![](Assets/login-diagram.png)\n\nTo make a state transition diagram like above _with additional effects_, follow these steps:\n\n```swift\n// 1. Define `State`s and `Input`s.\nenum State {\n    case loggedOut, loggingIn, loggedIn, loggingOut\n}\n\nenum Input {\n    case login, loginOK, logout, logoutOK\n    case forceLogout\n}\n\n// Additional effects (`SignalProducer`s) while state-transitioning.\n// (NOTE: Use `SignalProducer.empty` for no effect)\nlet loginOKProducer = /* show UI, setup DB, request APIs, ..., and send `Input.loginOK` */\nlet logoutOKProducer = /* show UI, clear cache, cancel APIs, ..., and send `Input.logoutOK` */\nlet forceLogoutOKProducer = /* do something more special, ..., and send `Input.logoutOK` */\n\nlet canForceLogout: (State) -\u003e Bool = [.loggingIn, .loggedIn].contains\n\n// 2. Setup state-transition mappings.\nlet mappings: [Automaton\u003cState, Input\u003e.EffectMapping] = [\n\n  /*  Input   |   fromState =\u003e toState     |      Effect       */\n  /* ----------------------------------------------------------*/\n    .login    | .loggedOut  =\u003e .loggingIn  | loginOKProducer,\n    .loginOK  | .loggingIn  =\u003e .loggedIn   | .empty,\n    .logout   | .loggedIn   =\u003e .loggingOut | logoutOKProducer,\n    .logoutOK | .loggingOut =\u003e .loggedOut  | .empty,\n\n    .forceLogout | canForceLogout =\u003e .loggingOut | forceLogoutOKProducer\n]\n\n// 3. Prepare input pipe for sending `Input` to `Automaton`.\nlet (inputSignal, inputObserver) = Signal\u003cInput, NoError\u003e.pipe()\n\n// 4. Setup `Automaton`.\nlet automaton = Automaton(\n    state: .loggedOut,\n    input: inputSignal,\n    mapping: reduce(mappings),  // combine mappings using `reduce` helper\n    strategy: .latest   // NOTE: `.latest` cancels previous running effect\n)\n\n// Observe state-transition replies (`.success` or `.failure`).\nautomaton.replies.observeNext { reply in\n    print(\"received reply = \\(reply)\")\n}\n\n// Observe current state changes.\nautomaton.state.producer.startWithValues { state in\n    print(\"current state = \\(state)\")\n}\n```\n\nAnd let's test!\n\n```swift\nlet send = inputObserver.send(value:)\n\nexpect(automaton.state.value) == .loggedIn    // already logged in\nsend(Input.logout)\nexpect(automaton.state.value) == .loggingOut  // logging out...\n// `logoutOKProducer` will automatically send `Input.logoutOK` later\n// and transit to `State.loggedOut`.\n\nexpect(automaton.state.value) == .loggedOut   // already logged out\nsend(Input.login)\nexpect(automaton.state.value) == .loggingIn   // logging in...\n// `loginOKProducer` will automatically send `Input.loginOK` later\n// and transit to `State.loggedIn`.\n\n// 👨🏽 \u003c But wait, there's more!\n// Let's send `Input.forceLogout` immediately after `State.loggingIn`.\n\nsend(Input.forceLogout)                       // 💥💣💥\nexpect(automaton.state.value) == .loggingOut  // logging out...\n// `forceLogoutOKProducer` will automatically send `Input.logoutOK` later\n// and transit to `State.loggedOut`.\n```\n\nNote that **any sizes of `State` and `Input` will work using `ReactiveAutomaton`**, from single state (like above example) to covering whole app's states (like React.js + Redux architecture).\n\n## References\n\n1. [iOSDC 2016 (Tokyo, in Japanese)](https://iosdc.jp/2016/) (2016/08/20)\n    - [iOSDC Japan 2016 08/20 Track A / Reactive State Machine / 稲見 泰宏 - YouTube](https://www.youtube.com/watch?v=Yvz9H9AWGFM) (video)\n    - [Reactive State Machine (Japanese) // Speaker Deck](https://speakerdeck.com/inamiy/reactive-state-machine-japanese) (slide)\n2. [iOSConf SG (Singapore, in English)](http://iosconf.sg/) (2016/10/20-21)\n    - [Reactive State Machine - iOS Conf SG 2016 - YouTube](https://www.youtube.com/watch?v=Oau4JjJP3nA) (video)\n    - [Reactive State Machine // Speaker Deck](https://speakerdeck.com/inamiy/reactive-state-machine-1) (slide)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finamiy%2Freactiveautomaton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finamiy%2Freactiveautomaton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finamiy%2Freactiveautomaton/lists"}