Skip to content

Instantly share code, notes, and snippets.

@erdemuslu
Last active April 25, 2020 11:08
Show Gist options
  • Save erdemuslu/ba8606670312a7bece33018575208bed to your computer and use it in GitHub Desktop.
Save erdemuslu/ba8606670312a7bece33018575208bed to your computer and use it in GitHub Desktop.
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