Created
June 28, 2017 23:22
-
-
Save Willmo36/8ab76cfeac0b4aa3fbe82589c6cc638e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/**REMOTE DATA IMPLEMENTATION */ | |
type Idle = { key: "idle", data: null }; | |
type Loading = { key: "loading", data: boolean }; | |
type Success = { key: "success", data: string }; | |
type RemoteDataState = Idle | Loading | Success; | |
type LoadTransition = [Idle, Loading]; | |
type SuccessTransition = [Loading, Success]; | |
type IdleTransition = [Success, Idle]; | |
type RemoteDataTransition = LoadTransition | SuccessTransition | IdleTransition; | |
const makeRun2 = <State, Transition>() => <From extends State, To extends State>(t: [From, To] & Transition) => t[1]; | |
const run2 = makeRun2<RemoteDataState, RemoteDataTransition>(); | |
let idle: RemoteDataState = { key: "idle", data: null }; | |
let loading: RemoteDataState = { key: "loading", data: true }; | |
let success: RemoteDataState = { key: "success", data: "boo" }; | |
let myRequest: RemoteDataState = run2([idle, loading]); | |
let shouldBeBool = myRequest.data; | |
myRequest = run2([loading, success]); | |
let shouldBeString = myRequest.data; | |
run2([loading, idle]); //this fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment