FluxxKit

所属分类:其他
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2019-03-31 13:24:01
上 传 者sh-1993
说明:  iOS.中用于 React编程的单向数据流。,
(Unidirectional data flow for reactive programming in iOS.,)

文件列表:
.swift-version (4, 2018-04-16)
.swiftlint.yml (166, 2018-04-16)
.travis.yml (683, 2018-04-16)
Cartfile.private (43, 2018-04-16)
Cartfile.resolved (61, 2018-04-16)
Example/ (0, 2018-04-16)
Example/Example.xcodeproj/ (0, 2018-04-16)
Example/Example.xcodeproj/project.pbxproj (18375, 2018-04-16)
Example/Example.xcodeproj/project.xcworkspace/ (0, 2018-04-16)
Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata (152, 2018-04-16)
Example/Example.xcodeproj/xcshareddata/ (0, 2018-04-16)
Example/Example.xcodeproj/xcshareddata/xcschemes/ (0, 2018-04-16)
Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme (3343, 2018-04-16)
Example/Example.xcworkspace/ (0, 2018-04-16)
Example/Example.xcworkspace/contents.xcworkspacedata (225, 2018-04-16)
Example/Example/ (0, 2018-04-16)
Example/Example/AppDelegate.swift (298, 2018-04-16)
Example/Example/Assets.xcassets/ (0, 2018-04-16)
Example/Example/Assets.xcassets/AppIcon.appiconset/ (0, 2018-04-16)
Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json (1077, 2018-04-16)
Example/Example/Base.lproj/ (0, 2018-04-16)
Example/Example/Base.lproj/LaunchScreen.storyboard (1740, 2018-04-16)
Example/Example/Base.lproj/Main.storyboard (11043, 2018-04-16)
Example/Example/Info.plist (1442, 2018-04-16)
Example/Example/Repository.swift (1544, 2018-04-16)
Example/Example/RepositoryViewController.swift (1044, 2018-04-16)
Example/Example/UIView.swift (617, 2018-04-16)
Example/Example/ViewController.swift (2260, 2018-04-16)
Example/Example/ViewModel.swift (2316, 2018-04-16)
Example/Gemfile (47, 2018-04-16)
Example/Gemfile.lock (1804, 2018-04-16)
Example/Podfile (136, 2018-04-16)
Example/Podfile.lock (571, 2018-04-16)
FluxxKit.podspec (556, 2018-04-16)
FluxxKit.xcodeproj/ (0, 2018-04-16)
FluxxKit.xcodeproj/project.pbxproj (21542, 2018-04-16)
FluxxKit.xcodeproj/project.xcworkspace/ (0, 2018-04-16)
FluxxKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata (153, 2018-04-16)
... ...

# FluxxKit [![CI Status](http://img.shields.io/travis/keitaoouchi/FluxxKit.svg?style=flat)](https://travis-ci.org/keitaoouchi/FluxxKit) [![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://swift.org/) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Version](https://img.shields.io/cocoapods/v/FluxxKit.svg?style=flat)](http://cocoapods.org/pods/FluxxKit) [![License](https://img.shields.io/cocoapods/l/FluxxKit.svg?style=flat)](http://cocoapods.org/pods/FluxxKit) [![Platform](https://img.shields.io/cocoapods/p/FluxxKit.svg?style=flat)](http://cocoapods.org/pods/FluxxKit) ## Overview Unidirectional data flow for reactive programming in iOS. Flux and Reactive Programming. FluxxKit is a porting [facebook's flux implementation](https://github.com/facebook/flux) in Swift. ## Example To run the example project, clone the repo, and run `pod install` from the Example directory first. More complicated real world example like below is [here](https://github.com/keitaoouchi/FluxxKitExample). ![GIF](https://raw.githubusercontent.com/keitaoouchi/FluxxKitExample/master/sample.gif "GIF") ### Getting Started 1. State ```swift import FluxxKit import RxSwift final class ViewModel: StateType { var count = Variable(0) } ``` 2. Action ```swift extension ViewModel { enum Action: ActionType { case plus case minus } } ``` 3. Reducer ```swift extension ViewModel { final class Reducer: FluxxKit.Reducer { override func reduce(state: ViewModel, action: Action) { switch action { case .plus: state.count.value = state.count + 1 case .minus: state.count.value = state.count - 1 } } } } ``` 4. View Create store and register it to dispatcher, and bind store's state: ```swift import FluxxKit import RxSWift final class ViewController: UIViewController { @IBOutlet var counterLabel: UILabel! @IBOutlet var plusButton: UIButton! @IBOutlet var minusButton: UIButton! var store = Store( reducer: ViewModel.Reducer() ) override func viewDidLoad() { super.viewDidLoad() Dispatcher.shared.register(store: self.store) store.state.count.asObservable().observeOn(MainScheduler.instance) .subscribe(onNext: { [weak self] count in self?.counterLabel.text = "\(count)" }) } deinit { Dispatcher.shared.unregister(identifier: self.store.identifier) } } ``` Dispatch action with UI action: ```swift @IBAction func onTouchPlusButton(sender: Any) { Dispatcher.shared.dispatch(action: ViewModel.Action.plus) } @IBAction func onTouchMinusButton(sender: Any) { Dispatcher.shared.dispatch(action: ViewModel.Action.minus) } ``` ### Architecture (:ghost: nice diagram here :ghost:) ##### FLUX for Reactive Programming FluxxKit would not emit any event when state change like [flux](https://github.com/facebook/flux/blob/962bd9516e3fe2cf2050d7a9c27befa431c5dbca/src/stores/FluxStore.js#L78). Instead, we have RxSwift, ReactiveSwift, ReactiveKit or something else. All the stateful things could be implemented as Observable or Stream, and ViewController could bind and react to them. #### Flux ``` View -> Action -> Dispatcher -> (Middleware) -> Store -> Reducer -> Observable ``` - When a user interacts with a View(Controller), it propagates an `Action` - through a central `Dispatcher`, - to the various `Store`s that hold the application's data, - `state transition` occurs in some `Store` that could responds to dispatched `Action`, - which will emit new items to `Observable` property in these `Store`. #### Reactive Programming ``` Observable ---> View ``` - ViewController subscribes Store's `Observable` properties, - and react to it. ## Requirements | Target | Version | |-------------------|---------| | iOS | => 8.0 | | Swift | => 4.0 | ## Installation FluxxKit is available through [CocoaPods](http://cocoapods.org) or [Carthage](https://github.com/Carthage/Carthage). ### CocoaPods ```ruby pod "FluxxKit" ``` ### Carthage ``` github "keitaoouchi/FluxxKit" ``` for detail, please follow the [Carthage Instruction](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos) ## Author keitaoouchi, keita.oouchi@gmail.com ## License FluxxKit is available under the MIT license. See the LICENSE file for more info.

近期下载者

相关文件


收藏者