Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Time traveling with
ReSwift
@EliSawic
About me
Eliasz Sawicki
Blog: www.eliaszsawicki.com
Twitter: @EliSawic
@EliSawic
ReSwift
@EliSawic
ReSwift is a Redux-like
implementation of the
unidirectional data flow
architecture in Swift.
@EliSawic
Plan
• How did it all start?
@EliSawic
Plan
• How did it all start?
• How does it work?
@EliSawic
Plan
• How did it all start?
• How does it work?
• What are my thoughts?
@EliSawic
How did it all start?
@EliSawic
What do we use?
@EliSawic
React
@EliSawic
Flux
@EliSawic
Redux
@EliSawic
Unidirectional Data
Flow
@EliSawic
Unidirectional Data Flow
• one direction of state change
• immutable state
• modified by pure functions
@EliSawic
DevTools
@EliSawic
Recording
@EliSawic
Time travel
@EliSawic
Fun to work with
@EliSawic
Dan Abramov
@EliSawic
ReSwift
@EliSawic
How does it work?
@EliSawic
Core Elements
• State
• Actions
• Reducers
• Store
@EliSawic
State
@EliSawic
State
@EliSawic
State
struct AppState: StateType, HasNavigationState {
var user: User
var navigationState: NavigationState
}
@EliSawic
Actions
@EliSawic
Actions
struct UpdateUserName: Action {
let name: String
init(_ name: String) {
self.name = name
}
}
@EliSawic
Action Creator
@EliSawic
Reducer
@EliSawic
Reducer
(Action, State?) -> State
@EliSawic
Update state
func handleAction(action: Action, state: AppState?) -> AppState {
return AppState(
user: userReducer(action, ...
Reducer
func userReducer(action: Action, user: User?) -> User {
var resultUser = user ?? User()
switch action {
case let a...
Store
@EliSawic
Receives our letters
@EliSawic
Manage changes
@EliSawic
Notify about changes
@EliSawic
Store
protocol Store {
init(reducer: Reducer, state: State)
func subscribe(subscriber: Subscriber)
func dispatch(action: A...
@EliSawic
Event
@EliSawic
Send letter
@EliSawic
Receive letters
@EliSawic
Manage changes
@EliSawic
Notify about changes
@EliSawic
React to state
changes
@EliSawic
What are my
thoughts?
@EliSawic
DevTools
@EliSawic
Remember
@EliSawic
Keep reducers fast
@EliSawic
No side effects in
Reducers
@EliSawic
Avoid heavy
application state
@EliSawic
One way of changing
state
@EliSawic
Why?
@EliSawic
Easy to understand
what is going on
@EliSawic
Easy testing
@EliSawic
DevTools - Time
traveling, Hot
reloading
@EliSawic
Fixing bugs with
friends
@EliSawic
Why not?
@EliSawic
Overwhelming
@EliSawic
Boilerplate
@EliSawic
Many ReSwift
components are in
POC state
@EliSawic
Easy to get stuck
@EliSawic
Against the
framework
@EliSawic
Check them out!
• Karl Bowden - @karlbowden
• Benjamin Encz - @benjaminencz
• Aleksander Rendtslev - @ARendtslev
• Dan Abr...
Check these out!
• https://karlbowden.com/reswift-prezzo/
• https://realm.io/news/benji-encz-unidirectional-data-flow-
swif...
Conclusion
@EliSawic
Thank you for your
attention
@EliSawic
Upcoming SlideShare
Loading in …5
×

Time traveling with ReSwift

355 views

Published on

Slides from "Time traveling with ReSwift" talk I gave at Mobile Warsaw meetup (17 Oct 2016).

Published in: Mobile
  • Be the first to comment

Time traveling with ReSwift

  1. 1. Time traveling with ReSwift @EliSawic
  2. 2. About me Eliasz Sawicki Blog: www.eliaszsawicki.com Twitter: @EliSawic @EliSawic
  3. 3. ReSwift @EliSawic
  4. 4. ReSwift is a Redux-like implementation of the unidirectional data flow architecture in Swift. @EliSawic
  5. 5. Plan • How did it all start? @EliSawic
  6. 6. Plan • How did it all start? • How does it work? @EliSawic
  7. 7. Plan • How did it all start? • How does it work? • What are my thoughts? @EliSawic
  8. 8. How did it all start? @EliSawic
  9. 9. What do we use? @EliSawic
  10. 10. React @EliSawic
  11. 11. Flux @EliSawic
  12. 12. Redux @EliSawic
  13. 13. Unidirectional Data Flow @EliSawic
  14. 14. Unidirectional Data Flow • one direction of state change • immutable state • modified by pure functions @EliSawic
  15. 15. DevTools @EliSawic
  16. 16. Recording @EliSawic
  17. 17. Time travel @EliSawic
  18. 18. Fun to work with @EliSawic
  19. 19. Dan Abramov @EliSawic
  20. 20. ReSwift @EliSawic
  21. 21. How does it work? @EliSawic
  22. 22. Core Elements • State • Actions • Reducers • Store @EliSawic
  23. 23. State @EliSawic
  24. 24. State @EliSawic
  25. 25. State struct AppState: StateType, HasNavigationState { var user: User var navigationState: NavigationState } @EliSawic
  26. 26. Actions @EliSawic
  27. 27. Actions struct UpdateUserName: Action { let name: String init(_ name: String) { self.name = name } } @EliSawic
  28. 28. Action Creator @EliSawic
  29. 29. Reducer @EliSawic
  30. 30. Reducer (Action, State?) -> State @EliSawic
  31. 31. Update state func handleAction(action: Action, state: AppState?) -> AppState { return AppState( user: userReducer(action, user: state?.user), navState: navReducer(action, navState: state?.navState) ) } @EliSawic
  32. 32. Reducer func userReducer(action: Action, user: User?) -> User { var resultUser = user ?? User() switch action { case let action as UpdateUserName: resultUser.name = action.name case let action as UpdateUserSurname: resultUser.surname = action.surname case let action as UpdateUserPresentationTitle: resultUser.presentationTitle = action.title default: break } return resultUser } @EliSawic
  33. 33. Store @EliSawic
  34. 34. Receives our letters @EliSawic
  35. 35. Manage changes @EliSawic
  36. 36. Notify about changes @EliSawic
  37. 37. Store protocol Store { init(reducer: Reducer, state: State) func subscribe(subscriber: Subscriber) func dispatch(action: Action) } @EliSawic
  38. 38. @EliSawic
  39. 39. Event @EliSawic
  40. 40. Send letter @EliSawic
  41. 41. Receive letters @EliSawic
  42. 42. Manage changes @EliSawic
  43. 43. Notify about changes @EliSawic
  44. 44. React to state changes @EliSawic
  45. 45. What are my thoughts? @EliSawic
  46. 46. DevTools @EliSawic
  47. 47. Remember @EliSawic
  48. 48. Keep reducers fast @EliSawic
  49. 49. No side effects in Reducers @EliSawic
  50. 50. Avoid heavy application state @EliSawic
  51. 51. One way of changing state @EliSawic
  52. 52. Why? @EliSawic
  53. 53. Easy to understand what is going on @EliSawic
  54. 54. Easy testing @EliSawic
  55. 55. DevTools - Time traveling, Hot reloading @EliSawic
  56. 56. Fixing bugs with friends @EliSawic
  57. 57. Why not? @EliSawic
  58. 58. Overwhelming @EliSawic
  59. 59. Boilerplate @EliSawic
  60. 60. Many ReSwift components are in POC state @EliSawic
  61. 61. Easy to get stuck @EliSawic
  62. 62. Against the framework @EliSawic
  63. 63. Check them out! • Karl Bowden - @karlbowden • Benjamin Encz - @benjaminencz • Aleksander Rendtslev - @ARendtslev • Dan Abramov - @danAbramov @EliSawic
  64. 64. Check these out! • https://karlbowden.com/reswift-prezzo/ • https://realm.io/news/benji-encz-unidirectional-data-flow- swift/ • https://github.com/reactjs/redux • https://github.com/ReSwift/ReSwift @EliSawic
  65. 65. Conclusion @EliSawic
  66. 66. Thank you for your attention @EliSawic

×