An experimental time traveling state store for SwiftUI

Overview

SwiftUI Time Travel

A SwiftUI state store and view that allow you to scrub through an application's state.

This is a super rough prototype: it's only meant to serve as an example of what can be done using SwiftUI.

animated gif


How this works

Any view hierarchy can use time travel: in the provided todo app, ContentView adds time travel like this:

struct ContentView : View {
    var body: some View {
        TimeTravelView(initialState: TodoState()) {
            TodoListView()
        }
    }
}

Then you can use @EnvironmentObject to access the state store from views within the hierarchy.

struct MyView: View {

    @EnvironmentObject var store: Store<TodoState>

    var body: some View {
        Text("Count: \(store.state.todoItems.count)")
    }
}

To update your application's state, use the dispatch method on the store:

struct MyView: View {

    @EnvironmentObject var store: Store<MyState>

    var body: some View {
        VStack(spacing: 10) {
            Text("Count: \(store.state.todoItems.count)")
            HStack(spacing: 10) {
                Button(action: { self.store.dispatch(event: .someEventName) }) {
                    Text("Do Something")
                }
            }
        }
    }
}

For time travel to work, all state must be accessed like this. Any state that is stored outside of the single Store<StateType> will not be controlled by the time travel view. This means that local view state (using @State) should be used sparingly (if at all).

Internally, the store keeps a stack of all states that have occured – the slider controls which of those states is used as the active (current) state.

You might also like...
🌾 Harvest: Apple's Combine.framework + State Machine, inspired by Elm.
🌾 Harvest: Apple's Combine.framework + State Machine, inspired by Elm.

NOTE: This repository has been discontinued in favor of Actomaton. 🌾 Harvest Apple's Combine.framework (from iOS 13) + State Machine, inspired by Elm

A super simple library for state management with unidirectional data flow.
A super simple library for state management with unidirectional data flow.

OneWay 🚧 OneWay is still experimental. As such, expect things to break and change in the coming months. OneWay is a super simple library for state ma

Streams of values over time
Streams of values over time

Streams of values over time. Tailored for Swift. 🚄 Release Roadmap Getting Started Learn about the Core Reactive Primitives in ReactiveSwift, and Bas

Open source implementation of Apple's Combine framework for processing values over time.
Open source implementation of Apple's Combine framework for processing values over time.

OpenCombine Open-source implementation of Apple's Combine framework for processing values over time. The main goal of this project is to provide a com

A powerful, minimal and composable architecture for building reactive iOS apps with SwiftUI or UIKit

SourceArchitecture A simple yet powerful framework for reactive programming with only a minimal optimized set of types. Sources are self-contained, hi

Sample iOS application in SwiftUI presenting Redux architecture
Sample iOS application in SwiftUI presenting Redux architecture

SwiftUI-Redux-Demo Sample iOS application in SwiftUI presenting Redux architecture. My full article about Redux in detail you will find here: Redux ar

Netflix Onboarding made with SwiftUI
Netflix Onboarding made with SwiftUI

OnBoardSwiftUI-Netflix Netflix Onboarding made with SwiftUI.

💎 Redux like architecture for SwiftUI
💎 Redux like architecture for SwiftUI

Simple Architecture like Redux Installation SPM dependencies: [ .package(url: "https://github.com/gre4ixin/ReduxUI.git", .upToNextMinor(from: "1.0

Flux for SwiftUI, inspired by Vuex
Flux for SwiftUI, inspired by Vuex

⚠️ Fluxus is no longer maintained, and may not be using latest SwiftUI best practices. 👉 I encourage you to look at the source of Fluxus. If you do,

Comments
  • Update for Xcode 11.1

    Update for Xcode 11.1

    Hi @timdonnelly 👋

    This project is outdated, so I updated the code to Xcode 11.1.

    BTW I also wrote my own time-travelling demo in https://github.com/inamiy/Harvest-SwiftUI-Gallery/pull/3 if you are interested 🙂

    P.S. I had some difficulty for working-around with SwiftUI's navigation / modal 2-way-binding, so it would be great if you have some good solution for time-travelling through those built-in UIs.

    opened by inamiy 1
Owner
Tim Donnelly
Tim Donnelly
🟣 Verge is a very tunable state-management engine on iOS App (UIKit / SwiftUI) and built-in ORM.

Verge.swift ?? An effective state management architecture for iOS - UIKit and also SwiftUI ?? _ An easier way to get unidirectional data flow _ _ Supp

VergeGroup 478 Dec 29, 2022
A lightweight Elm-like Store for SwiftUI

ObservableStore A simple Elm-like Store for SwiftUI, based on ObservableObject. ObservableStore helps you craft more reliable apps by centralizing all

Subconscious 28 Nov 8, 2022
🤖 RxSwift + State Machine, inspired by Redux and Elm.

RxAutomaton RxSwift port of ReactiveAutomaton (State Machine). Terminology Whenever the word "signal" or "(signal) producer" appears (derived from Rea

Yasuhiro Inami 719 Nov 19, 2022
Predictable state container for Swift too

ReduxSwift ReduxSwift is a minimal Swift port of Redux, a popular JavaScript library for application state management. Functionality Centralized State

Lucas Sunsi Abreu 38 Oct 6, 2020
Unidirectional State Management Architecture for Swift - Inspired by Vuex and Flux

Unidirectional State Management Architecture for Swift - Inspired by Vuex and Flux Introduction VueFlux is the architecture to manage state with unidi

Ryo Aoyama 324 Dec 17, 2022
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.

About Architecture concerns RxReduce Installation The key principles How to use RxReduce Tools and dependencies Travis CI Frameworks Platform Licence

RxSwift Community 125 Jan 29, 2022
CMPSC475 Final Project, ArboretumID Application allows users to explore the Penn State Arboretum, identify plants and learn about the exhibits!

ArboretumID: CMPSC475 Final Project Taylan Unal (@taylanu) About ArboretumID ArboretumIdentifier (ArboretumID) is an app that enhances the Penn State

Taylan 1 Nov 27, 2021
Redux for Swift - a predictable state container for Swift apps

Merge / deprecation announcement: ReduxKit and Swift-Flow have joined forces! The result is ReSwift. The nitty gritty: We decided to deprecate ReduxKi

null 613 Jan 3, 2023
MVVM + FLUX iOS Instagram client in Swift, eliminates Massive View Controller in unidirectional event/state flow manner

CZInstagram MVVM + FLUX iOS Instagram client in Swift, eliminates Massive View Controller in unidirectional event/state flow manner. Unidirectional Da

Cheng Zhang 56 Nov 1, 2022
Elegant state machine for Swift.

SwiftState Elegant state machine for Swift. Example enum MyState: StateType { case state0, state1, state2 } // setup state machine let machine = S

ReactKit 885 Dec 16, 2022