-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elmer Bulthuis
committed
Dec 3, 2019
1 parent
62cd4c8
commit fef826c
Showing
4 changed files
with
35 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extern crate reduxr; | ||
|
||
use super::*; | ||
use reduxr::Dispatch; | ||
use std::sync::Mutex; | ||
|
||
pub fn create_switch_middleware() -> impl FnOnce(Dispatch<State, Action>) -> Dispatch<State, Action> | ||
{ | ||
let mutex = Mutex::new(()); | ||
|
||
|next| { | ||
Box::new(move |store, action| { | ||
next(store, action); | ||
|
||
if let Action::Switch = action { | ||
let _lock = mutex.lock(); | ||
let state = store.get_state(); | ||
if state.select_power() { | ||
store.dispatch(Action::TurnOff); | ||
} else { | ||
store.dispatch(Action::TurnOn); | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters