Last active
October 16, 2021 15:16
-
-
Save yarigpopov/da9bc61d1e60c52d96d47977ab16d9f1 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
import Component from '@glimmer/component'; | |
import { action } from '@ember/object'; | |
import { useMachine } from 'ember-statecharts'; | |
import { use } from 'ember-usable'; | |
import async from './async/-machine'; | |
function noop() {} | |
export default class Async extends Component { | |
@use statechart = useMachine(async).withContext({ | |
trigger: this.args.trigger, | |
onSuccess: this.args.onSuccess || noop, | |
onError: this.args.onError || noop, | |
}); | |
get isIdle() { | |
return this.statechart.state.matches('idle'); | |
} | |
get isBusy() { | |
return this.statechart.state.matches('busy'); | |
} | |
get didSucceed() { | |
return this.statechart.state.matches('success'); | |
} | |
get didError() { | |
return this.statechart.state.matches('error'); | |
} | |
@action | |
trigger() { | |
this.statechart.send('DO'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment