Guest User

Untitled

a guest
Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // - 1 -
  2. import { just, Maybe, nothing } from 'maybeasy';
  3. import { action, computed, observable } from 'mobx';
  4. import { Alert } from './types';
  5.  
  6. class AlertsStore {
  7. // - 2 -
  8. @observable
  9. alerts: Alert[] = [];
  10.  
  11. // - 3 -
  12. @computed
  13. get current(): Maybe<Alert> {
  14. return this.alerts.length === 0 ? nothing() : just(this.alerts[0]);
  15. }
  16.  
  17. // - 4 -
  18. @action
  19. hide = () => {
  20. if (this.alerts.length > 0) {
  21. this.alerts[0].display = false;
  22. }
  23. };
  24.  
  25. // - 5 -
  26. @action
  27. process = () => {
  28. this.alerts = this.alerts.slice(1);
  29. };
  30.  
  31. // - 6 -
  32. @action
  33. push = (alert: Alert) => {
  34. this.hide();
  35. this.alerts.push({ ...alert, display: true });
  36. };
  37. }
  38.  
  39. // - 7 -
  40. const alertsStore = new AlertsStore();
  41. export default alertsStore;
Add Comment
Please, Sign In to add comment