-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
4 changed files
with
64 additions
and
17 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
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,37 @@ | ||
import 'package:redux/redux.dart'; | ||
import 'package:redux_tut/redux/actions.dart'; | ||
import 'store.dart'; | ||
|
||
bool isNumeric(String c) { | ||
/// isNumeric takes a string of length 1 | ||
/// returns true if string is numeric, returns false otherwise | ||
return c.compareTo('0') >= 0 && c.compareTo('9') <= 0; | ||
} | ||
|
||
void appStateMiddleware(Store<AppState> store, dynamic action, NextDispatcher next) { | ||
print("In the middleware"); | ||
|
||
if (action is UpdateKm) { | ||
String cleanedString = ''; | ||
for (String c in action.payload.split('')) { | ||
if (isNumeric(c)) { | ||
print("Adding $c to cleanedString"); | ||
cleanedString += c; | ||
print("cleanedString is $cleanedString"); | ||
} else { | ||
print("$c is not recognized as numeric"); | ||
} | ||
} | ||
|
||
store.dispatch(UpdateKmCleaned(cleanedString)); | ||
} else if (action is Convert) { | ||
print("Action is convert"); | ||
double kmAsDouble = double.parse(store.state.km); | ||
double milesAsDouble = kmAsDouble * 0.621371; | ||
|
||
store.dispatch(UpdateMiles(milesAsDouble.toString())); | ||
} | ||
|
||
next(action); | ||
} |
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