不論是 redux-thunk 或是 redux-saga,他們的基底都是 redux,所以就由 redux 的基礎開始看起。
接下來會以官方最簡單也最核心的 To-Do App demo 作為一步步推演、展示 redux 的核心
在一個 To-Do App 裡面,我們可以設想到會有兩個物件在互相作動
// Model| class ViewController: UIViewController { | |
| @IBOutlet weak var countingLabel: UILabel! | |
| private var timer: NSTimer? | |
| private var startTimeStamp: Int = 0 | |
| private var startCountingValue: Int = 0 | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| } |
| import UIKit | |
| class CountingLabel: UILabel { | |
| enum CountingMode: Int { | |
| case Decrease = -1 | |
| case Increase = 1 | |
| } | |
| var countingMode: CountingMode = .Decrease | |
| var isCounting: Bool = false |
| // | |
| // CircularProgress.swift | |
| // CHProgressSuit | |
| // | |
| // Created by Calvin on 6/26/16. | |
| // Copyright © 2016 CapsLock. All rights reserved. | |
| // | |
| import UIKit | |
| import CHCubicBezier |
| import UIKit | |
| import CHCubicBezier | |
| class CountingLabel: UILabel { | |
| var duration: Float = 0 | |
| var easingControlPoints: (x1: Double, y1: Double, x2: Double, y2: Double)? { | |
| didSet { | |
| cubicBezier = CubicBezier(controlPoints: easingControlPoints!) | |
| } | |
| } |
| import UIKit | |
| import CHCubicBezier | |
| class CountingLabel: UILabel { | |
| var duration: Float = 0 | |
| var easingControlPoints: (x1: Double, y1: Double, x2: Double, y2: Double)? { | |
| didSet { | |
| cubicBezier = CubicBezier(controlPoints: easingControlPoints!) | |
| } | |
| } |
| func test_changeContentView() { | |
| let xctExpectation = expectation(description: "Wait for carousel auto slide.") | |
| let carouselView = self.app.scrollViews.element | |
| let alertView = self.app.alerts.element | |
| DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 4.5) { [unowned self] in | |
| carouselView.tap() | |
| XCTAssertTrue(alertView.staticTexts["You selected page: 1 in carousel."].exists, "CarouselView should auto slides to second .") | |
| import UIKit | |
| class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { | |
| @IBOutlet var collectionView: UICollectionView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| self.collectionView.dataSource = self | |
| self.collectionView.delegate = self |
不論是 redux-thunk 或是 redux-saga,他們的基底都是 redux,所以就由 redux 的基礎開始看起。
接下來會以官方最簡單也最核心的 To-Do App demo 作為一步步推演、展示 redux 的核心
在一個 To-Do App 裡面,我們可以設想到會有兩個物件在互相作動
// Model| // Verify with FB console. | |
| app.get('/fb-subscribe', (req, res, next) => { | |
| if (req.param('hub.mode') == 'subscribe' && req.param('hub.verify_token') == process.env.VERIFY_TOKEN) { | |
| res.send(req.param('hub.challenge')); | |
| } else { | |
| res.sendStatus(400); | |
| } | |
| }); | |
| // Subscriber for receiving FB notification. | |
| app.post('/fb-subscribe', |