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
import Service from '@ember/service'; | |
import { tracked } from '@glimmer/tracking'; | |
export default class DogDataService extends Service { | |
@tracked data: IDog = null; | |
@tracked status: Status = Status.loading; | |
@tracked error: Error = null; | |
constructor() { | |
super(...arguments); |
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
import { Machine } from "xstate"; | |
function noop() {} | |
const async = Machine( | |
{ | |
initial: "idle", | |
context: { | |
trigger: noop, | |
onSuccess: noop, |
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
import React from "react"; | |
import async from "./async-machine"; | |
import { interpret } from "xstate"; | |
function noop() {} | |
// create a Provider/Consumer pair | |
const AsyncContext = React.createContext({}); | |
AsyncContext.displayName = "Async"; |
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
import { useMachine } from "@xstate/react"; | |
import async from "./async-machine"; | |
function noop() {} | |
function useAsync({ trigger, onSuccess, onError } = {}) { | |
const [current, send] = useMachine( | |
async.withContext({ | |
trigger: trigger || noop, | |
onSuccess: onSuccess || noop, |
OlderNewer