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
fn update_gravity_visuals( | |
mut visuals_query: Query<(&mut Path, &mut DrawMode, &mut GravityRing)>, | |
gravity_source: Res<GravitySource>, | |
) { | |
let level_bounds_radius_pixels = LEVEL_BOUNDS_RADIUS_METERS * PIXELS_PER_METER; | |
let gravity_source_radius_pixels = GRAVITY_SOURCE_RADIUS_METERS * PIXELS_PER_METER; | |
let min_radius = gravity_source_radius_pixels; | |
// fade to nothing just before the ring hits the terrain | |
let max_radius = level_bounds_radius_pixels; | |
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
export function main() { | |
let userRequest: RemoteData<User, Error> = Loading; | |
let translationsRequest: RemoteData<Translations, Error> = Loading; | |
let appState: AppState = Initializing; | |
fetchUser() | |
.then(response => { | |
userRequest = Success(response); | |
if (isSuccess(userRequest) && isSuccess(translationsRequest)) { |
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
function render(appState: AppState) { | |
switch (appState.type) { | |
case "Initializing": | |
return "Loading..."; | |
case "Ready": | |
const { username } = appState.user; | |
const { greeting } = appState.translations; | |
return `${greeting}, ${username}`; |
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
interface Initializing { | |
type: "Initializing"; | |
} | |
interface Ready { | |
type: "Ready"; | |
user: User; | |
translations: Translations; | |
} |
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
function render( | |
userRequest: RemoteData<User, Error>, | |
translationsRequest: RemoteData<Translations, Error> | |
) { | |
if (isLoading(userRequest) || isLoading(translationsRequest)) { | |
return "Loading..."; | |
} else if (isSuccess(userRequest) && isSuccess(translationsRequest)) { | |
const { username } = userRequest.data; | |
const { greeting } = translationsRequest.data; | |
return `${greeting}, ${username}`; |
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
export function isNotAsked<T, E>( | |
remoteData: RemoteData<T, E> | |
): remoteData is NotAsked { | |
return remoteData.type === "NotAsked"; | |
} | |
export function isLoading<T, E>( | |
remoteData: RemoteData<T, E> | |
): remoteData is Loading { | |
return remoteData.type === "Loading"; |
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
export function main() { | |
let userRequest: Data = { type: "Loading" }; | |
fetchData() | |
.then(response => { | |
userRequest = { type: "Success", data: response }; | |
}) | |
.catch(error => { | |
userRequest = { type: "Failure", error }; | |
}); |
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
interface User { | |
username: string; | |
email: string; | |
} | |
type Translations = { [key: string]: string }; | |
export function main() { | |
let userRequest: RemoteData<User, Error> = Loading; | |
let translationsRequest: RemoteData<Translations, Error> = Loading; |
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
type Data = | |
| { | |
type: "Loading"; | |
} | |
| { | |
type: "Success"; | |
data: User; | |
} | |
| { | |
type: "Failure"; |
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
interface NotAsked { | |
type: "NotAsked"; | |
} | |
interface Loading { | |
type: "Loading"; | |
} | |
interface Success<T> { | |
type: "Success"; |
NewerOlder