• Stars
    star
    32
  • Rank 801,431 (Top 16 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚛️ GoodReactor is a Redux-inspired Reactor framework for iOS developed using Swift. It enables seamless communication between the View Model, View Controller, and Coordinator through state and navigation functions. It ensures no side-effects by interacting with dependencies outside of the Reduce function. Integrate it with using SPM!

Logo

GoodReactor

Check out the Documentation

iOS Version Swift Version Supported devices Contains Test Dependency Manager

GoodReactor is an adaptation of the Reactor framework that is Redux inspired. The view model communicates with the view controller via the State and with the Coordinator via the navigation function. You communicate to the viewModel via Actions Viewmodel changes state in the Reduce function Viewmodel interactes with dependencies outside of the Reduce function not to create side-effects

Link to the original reactor kit: https://github.com/ReactorKit/ReactorKit

Installation

Swift Package Manager

Create a Package.swift file and add the package dependency into the dependencies list. Or to integrate without package.swift add it through the Xcode add package interface.

import PackageDescription

let package = Package(
    name: "SampleProject",
    dependencies: [
        .Package(url: "https://github.com/GoodRequest/GoodReactor" from: "addVersion")
    ]
)

Usage

GoodReactor

ViewModel

In your ViewModel define State, Actions and Mutations

  • State defines all data that you work with
  • Action user actions that are sent from the ViewController.
  • Mutation represents state changes.
    struct State {

        var counterValue: Int

    }

    enum Action {

        case updateCounterValue(CounterMode)
        case goToAbout

    }

    enum Mutation {

        case counterValueUpdated(Int)

    }

In the mutate function define what will happen when certain actions are called:

func mutate(action: Action) -> AnyPublisher<Mutation, Never> {
    switch action {
        case .updateCounterValue(let mode):
        return updateCounter(mode: mode)
        }
}
    
func updateCounter(mode: CounterMode) -> AnyPublisher<Mutation,Never> {
    var actualValue = currentState.counterValue

    switch mode {
        case .increase:
        actualValue += 1

        case .decrease:
        actualValue -= 1
    }

    return Just(.counterValueUpdated(actualValue)).eraseToAnyPublisher()
}

Finally in the reduce function define state changes according to certain mutation:

    func reduce(state: State, mutation: Mutation) -> State {
        var state = state

        switch mutation {
        case .counterValueUpdated(let newValue):
            state.counterValue = newValue
        }

        return state
    }

ViewController

From ViewController you can send actions to ViewModel via Combine just like in our GoodReactor-Sample or like this:

viewModel.send(event: yourAction)

Then use combine to subscribe to state changes, so every time the state is changed, ViewController is updated as well:

viewModel.state
    .map { String($0.counterValue) }
    .removeDuplicates()
    .assign(to: \.text, on: counterValueLabel, ownership: .weak)
    .store(in: &cancellables)

GoodCoordinator

When viewModel's action is called, navigation function is called as well. There you can hande the app flow, for example:

func navigate(action: Action) -> AppStep? {
    switch action {
        case .goToAbout:
        return .home(.goToAbout)

        default:
        return .none
    }
}

License

GoodReactor repository is released under the MIT license. See LICENSE for details.

More Repositories

1

GoodPersistence

💾 GoodPersistence is an iOS library that simplifies caching data in keychain and UserDefaults. Using a property wrapper, it reduces the complexity of implementing caching mechanisms, making it easier for developers to focus on app functionality. Compatible with latest Swift and supports all iOS devices. Easy to install with SPM.
Swift
33
star
2

Temple

🗂️ This repository provides a guide to creating Xcode templates for iOS boilerplate code to save time and increase creativity in development. It simplifies the process and helps new team members get up to speed. A solution to Xcode's poorly documented templates.
Swift
32
star
3

GoodNetworking

📡 GoodNetworking is an iOS library written in Swift that simplifies HTTP networking by using GRSession and Encodable/DataRequest extensions. It supports latest Swift and all iOS devices, making it a powerful solution for managing network interactions and data encoding/decoding. The library is easy to install with SPM.
Swift
31
star
4

GoodUIKit

📑 GoodUIKit is a UIKit extensions library filled with reusable UI snippets for faster and more efficient iOS development. Boost productivity and streamline your workflow with ready-to-use UI components.
Swift
30
star
5

GRProvider

🚀UITableView and UICollectionView provider to simplify basic scenarios of showing the data.
Swift
28
star
6

GoodExtensions-iOS

📑 GoodExtensions is a collection of useful and frequently used Swift extensions for iOS development, designed to simplify and streamline common tasks.It helps developers write clean and concise code, saving time and effort while boosting productivity. Get access to a wealth of essential tools for iOS development in one convenient library.
Swift
28
star
7

express-joi-to-swagger

Simple tool for generating swagger API documentation from source code.
TypeScript
19
star
8

GoodIOSExtensions

🧾 GoodIOSExtensions is a collection of modules extending different aspects of your swift xcode project
Swift
18
star
9

GoodSwiftUI

📑 GoodSwiftUI is a comprehensive library filled with reusable SwiftUI snippets for faster and more efficient iOS development. This library offers a wide range of customizable UI components, designed to boost your productivity and streamline your development workflow. Save time and effort by leveraging pre-made, tested, and ready-to-use code.
Swift
17
star
10

AppDebugMode-iOS

🐛 App Debug Mode 🐞 for iOS. Allows special debug privileges.
Swift
16
star
11

GoodSwift

Some good swift extensions, handfully crafted by GoodRequest team.
Swift
9
star
12

spongly-dapp-public

TypeScript
3
star
13

GoodPagerIndicator

Kotlin
2
star
14

joi-type-extract

Extract type from Joi schema
2
star
15

spongly-contracts

🪸 Smart contracts for spongly protocol
TypeScript
2
star
16

BackupBuddy

Simple Bash app for backing up your database or filesystem data.
Shell
2
star
17

GoodCoordinator-iOS

🧭 Simplified programmatic navigation in SwiftUI
Swift
2
star
18

Safe

Safe enables sharing confidential information with a limited number of views and overall lifetime.
HTML
2
star
19

test-coverage-push-script

JavaScript
1
star
20

internship_ios

HTML
1
star
21

Zoom

Kotlin optics library for immutable data manipulation
Kotlin
1
star
22

GoodLogger

Swift
1
star
23

joi-messages-extractor

Script for extracting joi messages. Useful for translations.
TypeScript
1
star
24

BackendAssignment-Fitness

TypeScript
1
star
25

clean-s3

snippet for S3 cleaner integrated with bullMQ
TypeScript
1
star