-
Notifications
You must be signed in to change notification settings - Fork 71
/
Store.js
81 lines (65 loc) · 1.37 KB
/
Store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { EventEmitter } from 'events';
import Constants from './Constants';
export default class PopupStore extends EventEmitter {
constructor(props) {
super(props);
this.id = 1;
this.popups = {};
this.queue = [];
this.active = null;
this.plugins = {};
}
/**
* Get popup ID
*/
getId() {
return `id_${this.id++}`;
}
/**
* Get active popup
* @returns {*}
*/
activePopup() {
return this.popups[this.active];
}
/**
* Close current popup
*/
close() {
if (!this.active) {
return false;
}
const id = this.active;
this.active = null;
this.emit(Constants.CLOSE, id);
this.dispatch();
this.value = null;
return id;
}
/**
* Dispatch next popup in queue
*/
dispatch() {
if (this.active || this.queue.length < 1) {
return false;
}
const id = this.queue.shift();
/** Set active */
this.active = id;
this.emit(Constants.SHOW, id);
return true;
}
/**
* Refresh popup position
* @param position
*/
refreshPosition(position) {
this.emit(Constants.REFRESH, position);
}
/**
* Clear queue
*/
clearQueue() {
this.queue = [];
}
}