Add snack bar store

This commit is contained in:
Jannis Mattheis 2018-03-31 18:55:04 +02:00 committed by Jannis Mattheis
parent 7836552bf5
commit 97fe5fb497
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import {EventEmitter} from 'events';
import dispatcher from './dispatcher';
class SnackBarStore extends EventEmitter {
messages = [];
next() {
return this.messages.shift();
}
hasNext() {
return this.messages.length !== 0;
}
handle(data) {
if (data.type === 'SNACK') {
this.messages.push(data.payload);
this.emit('change');
}
}
}
const store = new SnackBarStore();
dispatcher.register(store.handle.bind(store));
export default store;