Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A µFramework for handling side effects in a Redux ReSwift applcation.

License

NotificationsYou must be signed in to change notification settings

wickwirew/SideEffects

Repository files navigation

A µFramework for handling side effects in a ReduxReSwift applcation.

There are a lot of ways to manage side effects in a Redux application. Anything from using Thunks, Sagas, Observables and more. This is a different take on it from the normal approaches that plays to Swift's strengths, while taking inspiration fromredux-observables andngrx effects but without therx part. The goal ofSideEffects is to allow you to easiliy, and declaritivly define a function that runs anytime anAction of a defined type is dispatched. Allowing your views to dispatch vanilla Redux actions and be completely agnostic to any side effects.

Usage

For example if you have an actionItemSelected that is dispatch when ever an item is selected from a list.When its fired you might want to call an API to load the record from the database.

SideEffect(of:ItemSelected.self){ action, state, dispatchin    api.loadRecord(id: action.id){ response        // using the dispatch function you can dispatch a success/failure action.}}

There can also be multipleSideEffects defined per action. So to coninute on the previous example, if you also wanted to display the item's view controller as well. I could define anotherSideEffect to do so.

SideEffect(of:ItemSelected.self){ action, state, dispatchindispatch(SetRouteAction(...))}

Setup

Firstly, for ease of use first create a typealias for your application state's SideEffects.

typealiasSideEffect=Store<AppState>.SideEffect

Then define your applications SideEffects. The amount of SideEffects in the application can add up quick. For ease of organization it is recommended to separate them into multiple lists like so:

letmySideEffects:[SideEffect]=[SideEffect(of:ItemSelected.self){...},SideEffect(of:AnotherAction.self){...},]

Then create the middleware and add it to thestore

createSideEffectMiddleware(effects: mySideEffects+ moreSideEffects)

And thats it! 🎉

Installation

Carthage

You can install SideEffects via Carthage by adding the following line to yourCartfile:

github "wickwirew/SideEffects"

CocoaPods

You can install SideEffects via CocoaPods by adding the following line to yourPodfile:

pod 'SideEffects'

About

A µFramework for handling side effects in a Redux ReSwift applcation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp