Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created November 22, 2015 12:31
Show Gist options
  • Save MicheleBertoli/34c27120bdf9df90f9fb to your computer and use it in GitHub Desktop.
Save MicheleBertoli/34c27120bdf9df90f9fb to your computer and use it in GitHub Desktop.
Guestar
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;
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