All Projects → soxjke → Redux Reactiveswift

soxjke / Redux Reactiveswift

Licence: mit
Redux implementation over ReactiveSwift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Redux Reactiveswift

Moya Modelmapper
ModelMapper bindings for Moya.
Stars: ✭ 143 (+410.71%)
Mutual labels:  reactivecocoa
YoutubeEngine
Swift ReactiveCocoa lib for Youtube api
Stars: ✭ 24 (-14.29%)
Mutual labels:  reactivecocoa
Coderyi.github.io
Don't fork! coderyi's blog,about iOS ,CS and my code life.
Stars: ✭ 349 (+1146.43%)
Mutual labels:  reactivecocoa
Kickstarter Reactiveextensions
A collection of extensions to the ReactiveSwift framework.
Stars: ✭ 183 (+553.57%)
Mutual labels:  reactivecocoa
ACKReactiveExtensions
Set of useful extensions for ReactiveSwift & ReactiveCocoa
Stars: ✭ 17 (-39.29%)
Mutual labels:  reactivecocoa
Swiftrex
Swift + Redux + (Combine|RxSwift|ReactiveSwift) -> SwiftRex
Stars: ✭ 267 (+853.57%)
Mutual labels:  reactivecocoa
Reactivecocoa use
RAC的基础用法,提高开发效率
Stars: ✭ 89 (+217.86%)
Mutual labels:  reactivecocoa
Mhdevelopexample objective c
🔥🔥🔥 iOS开发技术要点汇总,核心功能配备文档。表情键盘布局、大文件分片上传、基于MVC的基类设计、MVVM+RAC实践、微信朋友圈实现方案等。
Stars: ✭ 937 (+3246.43%)
Mutual labels:  reactivecocoa
RacJS
implementation of RAC(OC) on JavaScript and replacement of RxJS
Stars: ✭ 13 (-53.57%)
Mutual labels:  reactivecocoa
Lightning
A Swift Multiplatform Single-threaded Non-blocking Web and Networking Framework
Stars: ✭ 312 (+1014.29%)
Mutual labels:  reactivecocoa
Zhuishushenqi
追书神器Swift版客户端(非官方)。 不断更新中......
Stars: ✭ 196 (+600%)
Mutual labels:  reactivecocoa
Moya-Gloss
Gloss bindings for Moya
Stars: ✭ 37 (+32.14%)
Mutual labels:  reactivecocoa
Swinjectmvvmexample
An example to use Swinject in MVVM architecture with ReactiveCococa
Stars: ✭ 301 (+975%)
Mutual labels:  reactivecocoa
Kzmooncommand
🔥 An awesome command for async operation with ReactiveCocoa
Stars: ✭ 164 (+485.71%)
Mutual labels:  reactivecocoa
Lpdmvvmkit
LPDMvvmKit - Elegant MVVM framework in Objective-C.
Stars: ✭ 400 (+1328.57%)
Mutual labels:  reactivecocoa
Easyreact
Are you confused by the functors, applicatives, and monads in RxSwift and ReactiveCocoa? It doesn't matter, the concepts are so complicated that not many developers actually use them in normal projects. Is there an easy-to-use way to use reactive programming? EasyReact is born for this reason.
Stars: ✭ 1,616 (+5671.43%)
Mutual labels:  reactivecocoa
Mvvmreactivecocoademo
ReactiveCocoa的知识点及MVVM模式运用(不断更新中....)
Stars: ✭ 255 (+810.71%)
Mutual labels:  reactivecocoa
Wechat
🔥 iOS 利用MVVM + RAC + ViewModel-Based Navigation来搭建微信(WeChat 7.0.0+)的整体基本架构,以及实现微信朋友圈、通讯录、下拉小程序、搜索等主要功能,代码规范惊为天人、注释详解令人发指、细节处理精益求精、核心功能配备文档、接近98%还原度的原生App视觉体验,代码不多,注释多。(持续更新,敬请期待,欢迎Star和Fork…)
Stars: ✭ 870 (+3007.14%)
Mutual labels:  reactivecocoa
Reactivecocoa
Cocoa framework and Obj-C dynamism bindings for ReactiveSwift.
Stars: ✭ 20,013 (+71375%)
Mutual labels:  reactivecocoa
Swiftgoal
MVVM + ReactiveCocoa 4, in Swift
Stars: ✭ 305 (+989.29%)
Mutual labels:  reactivecocoa

Redux-ReactiveSwift

Redux-ReactiveSwift

CI Status Code coverage status Version License Platform Carthage compatible

This library focuses on predictable state container implementation inspired by JS Redux. It benefits from ReactiveSwift. Using functional reactive approach & predictable state containers one should be able to write more clean & testable code :)

Example

The basic usage is pretty straightforward - one can create a store with State and reducer('s) of type (State, Event) -> State

import Redux_ReactiveSwift

class ViewModel {
    enum ButtonAction {
        case plus
        case minus
    }
    private(set) lazy var itemQuantityStore = Store<Int, ButtonAction>(state: 1, reducers: [self.itemQuantityReducer])
    private func itemQuantityReducer(state: Int, event: ButtonAction) -> Int {
        switch (event) {
            case .plus: return state + 1;
            case .minus: return state - 1;
        }
    }
}

Further, there can be benefit of binding data from Store using ReactiveSwift's UnidirectionaBinding:

class ViewController: UIViewController {
    @IBOutlet weak var quantityLabel: UILabel!
    @IBOutlet weak var plusButton: UIButton!
    @IBOutlet weak var minusButton: UIButton!
    lazy var viewModel = ViewModel()
    override func viewDidLoad() {
        super.viewDidLoad()
        quantityLabel.reactive.text <~ viewModel.itemQuantityStore.map(String.describing)
    }
}

To connect actions one can use ReactiveSwift's Action:

extension ViewModel {
    func action(for buttonAction: ButtonAction) -> Action<(), (), NoError> {
        return Action {
            return SignalProducer<(), NoError> { [weak self] in
                self?.itemQuantityStore.consume(event: buttonAction)
            }
        }
    }
}

class ViewController {
...
    override func viewDidLoad() {
        super.viewDidLoad()
        quantityLabel.reactive.text <~ viewModel.itemQuantityStore.map(String.describing)
        plusButton.reactive.pressed = CocoaAction(viewModel.action(for: .plus))
        minusButton.reactive.pressed = CocoaAction(viewModel.action(for: .minus))
    }
}

State changing logic is completely in one place. Forever. If we'd like to have something more advanced we can benefit of reducers chain:

extension ClosedRange {
    func clamp(_ value : Bound) -> Bound {
        return self.lowerBound > value ? self.lowerBound
            : self.upperBound < value ? self.upperBound
            : value
    }
}

class ViewModel {
    private func itemQuantityClamper(state: Int, event: ButtonAction) -> Int {
        return (0...10).clamp(state)
    }
    private(set) lazy var itemQuantityStore = Store<Int, ButtonAction>(state: 1, reducers: [self.itemQuantityReducer, self.itemQuantityClamper]
}

or it can be done with a single reducer with benefit of some kind of functional applyMap:

// This one looks ugly because tuple splatting was removed in Swift 4, thanks Chris Lattner!
func applyMap<R1, R2>(f2: @escaping (R1, R2) -> R1, mapper: @escaping (R1) -> R1) -> (R1, R2) -> R1 {
    return { (arg1, arg2) -> R1 in
        return mapper(f2(arg1, arg2))
    }
}
...
    private(set) lazy var itemQuantityStore = Store<Int, ButtonAction>(state: 1, reducers: [applyMap(f2: self.itemQuantityReducer, mapper: ClosedRange.clamp((0...10))]

Due to functional reactive spirit of solution you're limited only by your fantasy and Mr.Lattner's "enhancements" to Swift language. Some more cases of Store usage can be found in tests spec:

https://github.com/soxjke/Redux-ReactiveSwift/blob/master/Redux-ReactiveSwift/Tests/StoreSpec.swift

Requirements

Installation

Redux-ReactiveSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Redux-ReactiveSwift'

Redux-ReactiveSwift is available through Carthage. To install it, simply add the following line to your Podfile:

github "soxjke/Redux-ReactiveSwift"

Author

Petro Korienev, [email protected]

License

Redux-ReactiveSwift is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].