Last active
April 25, 2020 11:08
-
-
Save erdemuslu/ba8606670312a7bece33018575208bed to your computer and use it in GitHub Desktop.
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
import { | |
action, decorate, observable, runInAction, | |
} from 'mobx'; | |
import LyricsService from './Service'; | |
function Store() { | |
this.name = 'Ali'; | |
this.status = ''; | |
this.lyricsData = ''; | |
this.LyricsService = LyricsService; | |
this.updateName = (name) => { | |
this.name = name; | |
}; | |
this.getLyrics = async ({ artist, title }) => { | |
try { | |
this.status = 'loading'; | |
const result = await this.LyricsService.get({ artist, title }); | |
runInAction(() => { | |
this.status = 'done'; | |
this.lyricsData = result.lyrics.split('\n').join('<br />'); | |
}); | |
} catch (err) { | |
runInAction(() => { | |
this.status = 'error'; | |
this.data = ''; | |
}); | |
} | |
}; | |
} | |
decorate(Store, { | |
name: observable, | |
status: observable, | |
lyricsData: observable, | |
updateName: action, | |
getLyrics: action, | |
}); | |
export default new Store(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment