Created
November 22, 2015 12:31
-
-
Save MicheleBertoli/34c27120bdf9df90f9fb to your computer and use it in GitHub Desktop.
Guestar
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 _ from 'lodash'; | |
| import {EventEmitter} from 'events'; | |
| const CHANGE_EVENT = 'change'; | |
| const BaseStore = _.assign({}, EventEmitter.prototype, { | |
| emitChange() { | |
| this.emit(CHANGE_EVENT); | |
| }, | |
| addChangeListener(callback) { | |
| this.on(CHANGE_EVENT, callback); | |
| }, | |
| removeChangeListener(callback) { | |
| this.removeListener(CHANGE_EVENT, callback); | |
| } | |
| }); | |
| export default BaseStore; |
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 _ from 'lodash'; | |
| import AppDispatcher from '../dispatcher/AppDispatcher'; | |
| import WelcomeConstants from '../constants/WelcomeConstants'; | |
| import BaseStore from './BaseStore'; | |
| const _state = { | |
| message: 'Welcome to React Native' | |
| }; | |
| const _setStateMessage = message => _state.message = message; | |
| const WelcomeStore = _.assign({}, BaseStore, { | |
| getMessage() { | |
| return _state.message; | |
| } | |
| }); | |
| AppDispatcher.register(action => { | |
| switch(action.actionType) { | |
| case WelcomeConstants.SET_WELCOME_MESSAGE: | |
| _setStateMessage(action.message); | |
| WelcomeStore.emitChange(); | |
| break; | |
| } | |
| }); | |
| export default WelcomeStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment