Skip to content

Instantly share code, notes, and snippets.

@fernyettheplant
Created May 26, 2019 15:19
Show Gist options
  • Save fernyettheplant/9c3bbdf8dc213703361def977ee5479b to your computer and use it in GitHub Desktop.
Save fernyettheplant/9c3bbdf8dc213703361def977ee5479b to your computer and use it in GitHub Desktop.
import { Action, Module, Mutation, VuexModule } from 'vuex-module-decorators'
import { Inject } from 'inversify-props'
import KanyeQuote from '@/models/KanyeQuote'
import IKanyeWestService from '@/services/IKanyeWestService'
@Module
export default class KanyeWest extends VuexModule {
@Inject()
private kanyeWestService!: IKanyeWestService
public kanyeQuote: KanyeQuote | null = null
@Action
public async fetchKanyeQuote (): Promise<void> {
try {
const kanyeQuote = await this.kanyeWestService.getQuote()
this.context.commit('setKanyeQuote', kanyeQuote)
} catch (error) {
console.error(error)
}
}
@Mutation
public setKanyeQuote (newKanyeQuote: KanyeQuote): void {
this.kanyeQuote = newKanyeQuote
}
get quote (): string {
return this.kanyeQuote !== null ? this.kanyeQuote.quote : ''
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment