Learnings from developing a multiplayer game logic in elm as a finite state machine and exporting it as a npm module that is being used in 1. In mobile(react-native) client to play the game offline and to do optimistic updates when playing online. 2. In server(node) for scoring 3. In web client (react) as a desktop client.
1 of 39
Download to read offline
More Related Content
Forward JS 2017 | SF | Write applications as State Machines
8. 則 No Side effects
則 No Mutations (Observable)
則 Returns the same result
則 Explicit Dependencies
則 Clean
則 Understandable
則 Testable
則 Can be easily portable to any
framework
9. 則 Takes Function as an arguments and data structure
則 Operates on the data structure
則 Examples
則 Map
則 Reduce
11. 則 Takes a function
則 Takes an initial value
則 Run the function on the list
for each elements
則 Return the final value
14. 則 Caller needs to provide everything for the method
則 Dependencies
則 Relevant Data structures
則 Callee ask everything it needs from the caller
則 We need a wrapper around these pure functions that
encapsulate STATE
22. 則 A JS module that provides an interface to compute states
based on actions
則 All your business/core logic is in that transition function
則 It does not depends on any framework
則 All those are pure functions.
23. 則 Next state can be calculated just by passing the current state
with the action
則 It can be done on the server / client
則 All client are self sufficient to compute the next state
則 Works offline
33. 則 Convert ELM to JSON
則 Throws errors at the gate
則 Can combine encoders
34. Convert JSON to elm objects
則 Throws errors at the gate
則 Can combine
35. 則 Elm compiles to ES5
則 Import as a normal module
則 Export with the wrapper
36. 則 Structure application as a state machine
則 Modularize it to a single package
則 Hydrate and De-hydrate the engine when needed
則 To run the app offline
則 To do optimistic updates
37. 則 Write the engine/core logic in Elm
則 Compile to JS and export as a module.
則 Use encoders and decoders to convert messages and state though ports
則 Make Impossible states impossible
https://www.youtube.com/watch?v=IcgmSRJHu_8
則 Use Effects as Data
https://www.youtube.com/watch?v=6EdXaWfoslc