SwiftUI Todo app example using a React/Redux monolithic state store with flux like dispatch/reduce actions

Overview

SwiftUI-Todo-Redux

SwiftUI Todo Redux app example using a React/Redux monolithic state store with flux like dispatch/reduce actions

Background

SwiftUI based app using a centralized, 'monolithic' AppState() which binds to the UI using the Combine framework and a PassthroughSubject method. This architecture is based on the React/Redux pattern and has a few key benefits:

  1. Global app state is maintained in single global struct, let state = AppState()
  2. Testing and Previewing of individual views can then be isolated with local test states, eg., a local debug call to environmentObject(sampleStore) can be used for UI Previews anywhere in the app
  3. Isolating Actions from State allows for cleaner synchronous behavior, eg., handle both server based calls and local UI-only actions in the same method or flow
  4. Chnages to state are Reduced within a simple state machine method which can be easily tested

File Structure

The structure of the app follows a simple pattern of MVS: Models, Views and State. Models contain all the relevant state, separated into relevant gropus such as Tasks, Users, Authorization, etc. The models directory contains model definitions, as well as codecs and backing store (ie., API Services) for isolated testing of the models and their propoer storage. The states directory contains a combination of global app state, the sub-states or flux describiing the relevant groups (eg., Task, User), actions which the user initiates (eg., TaskActions or UserActions) and then trigger asynchronous server-based or synchronous actions. The result of the actions are then reduced (eg., TaskStateReducer or UserStateReducer) to subsequently modify the global app state.

The AppState structure holds referenes to the group states (ie., Tasks and User lists), as well as acts as a central dispatch point for both actions and handling any state updates via the Combine framework.

Finally, all UI Views are maintained within their respective hierarchy, with a Home or Root view driving all app navigation.

.
|____AppDelegate.swift
|____SceneDelegate.swift
|____views
| |____HomeView.swift
|____models
| |____User.swift
| |____UserResponse.swift
| |____Task.swift
|____states
| |____AppState.swift
| |____flux (substate)
| | |____FluxState.swift
| | |____UsersState.swift
| | |____TasksState.swift
| |____actions
| | |____Action.swift
| | |____UserActions.swift
| | |____TaskActions.swift
| |____reducers (statemachine)
| | |____Reducer.swift
| | |____UserStateReducer.swift
| | |____TaskStateReducer.swift

Notes

You might also like...
Here there is a simple example using watchOS and SwiftUI
Here there is a simple example using watchOS and SwiftUI

A Simple Demonstration Project using WatchOS + SwiftUI Description This project is a simple demonstration about how to create a WatchOS App using Swif

An example app with using ShazamKit
An example app with using ShazamKit

ShazamKitExample An example app with using ShazamKit. Check out a live demo on Twitter. Related Resources Introducing ShazamKit WWDC21 — Explore Shaza

SwiftUI Navigation example app

SwiftUINavigationExample SwiftUI Navigation example app. Navigation is managed by a single class called NavSwitches. This contains all the booleans th

An example project of using the new Character Controller component in RealityKit 2.0
An example project of using the new Character Controller component in RealityKit 2.0

CharacterController in RealityKit 2.0 An example project of using the new Character Controller component in RealityKit 2.0. Demo Tweet Usage Install a

An example of using the GPU on M1 arm64 Macs for basic compute functions

M1-GPU-Compute Using Swift and Apple's Metal API to utilize the GPUs on M1 equipped Macs Adding Two Arrays CPUs perform computations sequentially, wai

Uses Firestore to remotely store books that are sorted by genre locally.
Uses Firestore to remotely store books that are sorted by genre locally.

Uses Firestore to remotely store books that are sorted by genre locally. Books can be added, removed, or edited from within the app or on Firebase.

Advanced Catalyst Example with sidebar, list view, SwiftUI detail view, toolbar & AppKit bundle
Advanced Catalyst Example with sidebar, list view, SwiftUI detail view, toolbar & AppKit bundle

Advanced Catalyst Example This is an example of a Catalyst app using a three-column layout, with a primary toolbar. It includes topics such as: Drag &

SwiftUI + Combine + MVVM - Book search example
SwiftUI + Combine + MVVM - Book search example

CombineBookSearch SwiftUI + Combine + MVVM Example project of SwiftUI and Combine using MVVM architecture pattern.

Example on how to print a NSTableView from your app but then also add text to the print-out.
Example on how to print a NSTableView from your app but then also add text to the print-out.

NSTableView Printing Test This is a demo project so you can check out how printing a table could work. The goal here is to show tabular data on screen

Comments
  • Can't compile

    Can't compile

    /Users/user/test/SwiftUI-Todo-Redux/SwiftUI-Todo-Redux/views/tasks/TasksList.swift:30:26: Use of undeclared type 'Modal'

    There is no class Modal defined in your project. Any idea?

    opened by zhouhao27 0
Owner
moflo
moflo
REDUX like architecture sample for iOS

perdux_sample_swiftUI REDUX like architecture sample for iOS (target 14.*) Motivation: to share reactive architecture approach with single direction d

alexis 3 Jan 27, 2022
PushDispatcher-vapor - Simple Api to dispatch push to APNS with p8 file

PushDispatcher - Vapor The purpose of this application is to facilitate the test

Michel Anderson Lütz Teixeira 3 Oct 18, 2022
A basic todo app using swift

Toodoo A basic todo app Features Basics Today List Categorize Prioritize Future Tasks Support Pictures Reorder Tasks Cross platform Quick Entry Analyz

null 0 Nov 1, 2021
Demo project using React Native technology to create a simple iOS app to find music in iTunes

React Native, native iOS apps with JavaScript iTunesCatalog is a demo app that aims to show the React Native platform potential. There are included th

Alexis Santos Pérez 55 Feb 10, 2022
Demo app for SwiftUI state management

StateObject vs ObservedObject Demo Demo app for SwiftUI state management Run the app and push 3 buttons to increase each counter. Toggle one of the to

Serhii Kyrylenko 0 Oct 13, 2021
Todolist-swiftui - An example of using SwiftUI with CoreData

todolist-swiftui An example of using SwiftUI with CoreData Installation Install

null 0 Dec 30, 2021
🚀 React-Native App for rocket launches 🛰

A simple way to stay up to date with upcoming space launches, built with React-Native

Maxime Nory 257 Dec 24, 2022
Dribbble app built with React Native

A Dribbble app build with React Native.

Catalin Miron 2k Dec 29, 2022
iPhone app built with React Native for viewing houses for sale in the Northwest

Den is an iPhone app built with React Native for viewing houses for sale in the NW from rmls.com. After being frustrated with a site that hasn't changed since 2004, I decided to build a better viewing experience in the phone.

Asa Miller 464 Aug 31, 2022
An example of adding a faux notch using AppKit + SwiftUI

faux-notch An example of adding a faux notch using AppKit + SwiftUI What is this? It's a bare-bones example that renders a fake MacBook notch in macOS

Tanner Stokes 2 Nov 14, 2021