application/services/error-service.js
import Immutable from 'immutable';
import alt from './../alt';
import BaseService from './base-service';
/**
* Errors live in internal stack. Simply call the add() method to display a new error:
* <code>
* ErrorService.add('warning', 'Foo bar!');
* </code>
*/
class ErrorService extends BaseService {
updateError(error) {
return error;
}
add(type, message) {
const err = {type: type, message: message};
return (dispatch) => {
setTimeout(() => {
this.updateError(err);
}, 1);
};
}
}
const service = alt.createActions(ErrorService);
class ErrorsStore {
constructor() {
this.state = {
'error': {},
};
this.bindListeners({
'handleUpdateError': service.UPDATE_ERROR
});
}
handleUpdateError(error) {
this.setState({'error': error});
}
}
const store = alt.createStore(ErrorsStore, 'ErrorsStore');
export {service as ErrorService, store as ErrorsStore};