Last active
January 9, 2016 04:05
-
-
Save cacheflow/28be857f76ff3f010f65 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 {formatLyric} from '../utils/format.js'; | |
const AppStoreSetter = { | |
selected: "", | |
tweetText: "", | |
templateText: "", | |
clicked: false, | |
setTweetText(lyric) { | |
let templateTextLyric = lyric; | |
this.setTemplateText(templateTextLyric); | |
let formattedLyricForTweet = formatLyric(lyric); | |
this.tweetText = formattedLyricForTweet; | |
this.setClickedState(false); | |
}, | |
setSelected(action) { | |
this.selected = action; | |
}, | |
setTemplateText(lyric) { | |
this.templateText = lyric; | |
}, | |
setClickedState(bool) { | |
this.clicked = bool; | |
} | |
} | |
export default AppStoreSetter |
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 _AppDispatcher from '../dispatchers/app-dispatcher' | |
import AppConstants from '../constants/app-constants' | |
import {EventEmitter} from 'events'; | |
import AppStoreSetter from '../api/AppStoreSetter' | |
class AppStore extends EventEmitter{ | |
clickedState() { | |
return AppStoreSetter.clicked; | |
} | |
getSelected() { | |
return AppStoreSetter.selected; | |
} | |
getTweetText() { | |
return AppStoreSetter.tweetText; | |
} | |
getTemplateText() { | |
return AppStoreSetter.templateText; | |
} | |
emitChange() { | |
this.emit('CHANGE') | |
} | |
addChangeListener(callback) { | |
this.on('CHANGE', callback) | |
} | |
removeChangeListener(callback){ | |
this.removeChangeListener('CHANGE', callback) | |
} | |
} | |
let _AppStore = new AppStore(); | |
_AppDispatcher.register((action) => { | |
let payload = action.action; | |
switch(payload.type) { | |
case AppConstants.GET_LYRIC: | |
AppStoreSetter.setTweetText(payload.data); | |
break; | |
case AppConstants.UPDATE_CLICKED_STATUS: | |
AppStoreSetter.setClickedState(payload.data); | |
break; | |
} | |
_AppStore.emitChange() | |
}); | |
export default _AppStore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment