#427 Add capability to mutate middleware after store creation.

Open Malcolm Jarvis mjarvis

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 3 files from the diff.

@@ -29,7 +29,7 @@
Loading
29 29
        }
30 30
    }
31 31
32 -
    public var dispatchFunction: DispatchFunction!
32 +
    public lazy var dispatchFunction: DispatchFunction! = createDispatchFunction()
33 33
34 34
    private var reducer: Reducer<State>
35 35
@@ -41,6 +41,12 @@
Loading
41 41
    /// by default.
42 42
    fileprivate let subscriptionsAutomaticallySkipRepeats: Bool
43 43
44 +
    public var middleware: [Middleware<State>] {
45 +
        didSet {
46 +
            dispatchFunction = createDispatchFunction()
47 +
        }
48 +
    }
49 +
44 50
    /// Initializes the store with a reducer, an initial state and a list of middleware.
45 51
    ///
46 52
    /// Middleware is applied in the order in which it is passed into this constructor.
@@ -61,9 +67,18 @@
Loading
61 67
    ) {
62 68
        self.subscriptionsAutomaticallySkipRepeats = automaticallySkipsRepeats
63 69
        self.reducer = reducer
70 +
        self.middleware = middleware
64 71
72 +
        if let state = state {
73 +
            self.state = state
74 +
        } else {
75 +
            dispatch(ReSwiftInit())
76 +
        }
77 +
    }
78 +
79 +
    private func createDispatchFunction() -> DispatchFunction! {
65 80
        // Wrap the dispatch function with all middlewares
66 -
        self.dispatchFunction = middleware
81 +
        return middleware
67 82
            .reversed()
68 83
            .reduce(
69 84
                { [unowned self] action in
@@ -75,12 +90,6 @@
Loading
75 90
                    let getState = { [weak self] in self?.state }
76 91
                    return middleware(dispatch, getState)(dispatchFunction)
77 92
            })
78 -
79 -
        if let state = state {
80 -
            self.state = state
81 -
        } else {
82 -
            dispatch(ReSwiftInit())
83 -
        }
84 93
    }
85 94
86 95
    fileprivate func _subscribe<SelectedState, S: StoreSubscriber>(

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
ReSwift 0.01% 99.48%
Project Totals (6 files) 99.48%
Loading