@@ -10,122 +10,122 @@ import Card from './card';
10
10
* @returns {Object } An instance of Stack object.
11
11
*/
12
12
export const Stack = ( config ) => {
13
- let eventEmitter ;
14
- let index ;
15
- let springSystem ;
16
- let stack ;
17
-
18
- const construct = ( ) => {
19
- stack = { } ;
20
- springSystem = new rebound . SpringSystem ( ) ;
21
- eventEmitter = Sister ( ) ;
22
- index = [ ] ;
23
- } ;
24
-
25
- construct ( ) ;
26
-
27
- /**
28
- * Get the configuration object.
29
- *
30
- * @returns {Object }
31
- */
32
- stack . getConfig = ( ) => {
33
- return config ;
34
- } ;
35
-
36
- /**
37
- * Get a singleton instance of the SpringSystem physics engine.
38
- *
39
- * @returns {Sister }
40
- */
41
- stack . getSpringSystem = ( ) => {
42
- return springSystem ;
43
- } ;
44
-
45
- /**
46
- * Proxy to the instance of the event emitter.
47
- *
48
- * @param {string } eventName
49
- * @param {string } listener
50
- * @returns {undefined }
51
- */
52
- stack . on = ( eventName , listener ) => {
53
- eventEmitter . on ( eventName , listener ) ;
54
- } ;
55
-
56
- /**
57
- * Creates an instance of Card and associates it with an element.
58
- *
59
- * @param {HTMLElement } element
60
- * @param {boolean } prepend
61
- * @returns {Card }
62
- */
63
- stack . createCard = ( element , prepend ) => {
64
- const card = Card ( stack , element , prepend ) ;
65
- const events = [
66
- 'throwout' ,
67
- 'throwoutend' ,
68
- 'throwoutleft' ,
69
- 'throwoutright' ,
70
- 'throwoutup' ,
71
- 'throwoutdown' ,
72
- 'throwin' ,
73
- 'throwinend' ,
74
- 'dragstart' ,
75
- 'dragmove' ,
76
- 'dragend'
77
- ] ;
78
-
79
- // Proxy Card events to the Stack.
80
- events . forEach ( ( eventName ) => {
81
- card . on ( eventName , ( data ) => {
82
- eventEmitter . trigger ( eventName , data ) ;
83
- } ) ;
84
- } ) ;
85
-
86
- index . push ( {
87
- card,
88
- element
89
- } ) ;
90
-
91
- return card ;
92
- } ;
93
-
94
- /**
95
- * Returns an instance of Card associated with an element.
96
- *
97
- * @param {HTMLElement } element
98
- * @returns {Card|null }
99
- */
100
- stack . getCard = ( element ) => {
101
- const group = _ . find ( index , ( i ) => {
102
- if ( element . isEqualNode ( i . element ) ) {
103
- return i ;
104
- }
105
- } ) ;
106
-
107
- if ( group ) {
108
- return group . card ;
109
- }
110
-
111
- return null ;
112
- } ;
113
-
114
- /**
115
- * Remove an instance of Card from the stack index.
116
- *
117
- * @param {Card } card
118
- * @returns {null }
119
- */
120
- stack . destroyCard = ( card ) => {
121
- eventEmitter . trigger ( 'destroyCard' , card ) ;
122
-
123
- return _ . remove ( index , {
124
- card
125
- } ) ;
126
- } ;
127
-
128
- return stack ;
13
+ let eventEmitter ;
14
+ let index ;
15
+ let springSystem ;
16
+ let stack ;
17
+
18
+ const construct = ( ) => {
19
+ stack = { } ;
20
+ springSystem = new rebound . SpringSystem ( ) ;
21
+ eventEmitter = Sister ( ) ;
22
+ index = [ ] ;
23
+ } ;
24
+
25
+ construct ( ) ;
26
+
27
+ /**
28
+ * Get the configuration object.
29
+ *
30
+ * @returns {Object }
31
+ */
32
+ stack . getConfig = ( ) => {
33
+ return config ;
34
+ } ;
35
+
36
+ /**
37
+ * Get a singleton instance of the SpringSystem physics engine.
38
+ *
39
+ * @returns {Sister }
40
+ */
41
+ stack . getSpringSystem = ( ) => {
42
+ return springSystem ;
43
+ } ;
44
+
45
+ /**
46
+ * Proxy to the instance of the event emitter.
47
+ *
48
+ * @param {string } eventName
49
+ * @param {string } listener
50
+ * @returns {undefined }
51
+ */
52
+ stack . on = ( eventName , listener ) => {
53
+ eventEmitter . on ( eventName , listener ) ;
54
+ } ;
55
+
56
+ /**
57
+ * Creates an instance of Card and associates it with an element.
58
+ *
59
+ * @param {HTMLElement } element
60
+ * @param {boolean } prepend
61
+ * @returns {Card }
62
+ */
63
+ stack . createCard = ( element , prepend ) => {
64
+ const card = Card ( stack , element , prepend ) ;
65
+ const events = [
66
+ 'throwout' ,
67
+ 'throwoutend' ,
68
+ 'throwoutleft' ,
69
+ 'throwoutright' ,
70
+ 'throwoutup' ,
71
+ 'throwoutdown' ,
72
+ 'throwin' ,
73
+ 'throwinend' ,
74
+ 'dragstart' ,
75
+ 'dragmove' ,
76
+ 'dragend'
77
+ ] ;
78
+
79
+ // Proxy Card events to the Stack.
80
+ events . forEach ( ( eventName ) => {
81
+ card . on ( eventName , ( data ) => {
82
+ eventEmitter . trigger ( eventName , data ) ;
83
+ } ) ;
84
+ } ) ;
85
+
86
+ index . push ( {
87
+ card,
88
+ element
89
+ } ) ;
90
+
91
+ return card ;
92
+ } ;
93
+
94
+ /**
95
+ * Returns an instance of Card associated with an element.
96
+ *
97
+ * @param {HTMLElement } element
98
+ * @returns {Card|null }
99
+ */
100
+ stack . getCard = ( element ) => {
101
+ const group = _ . find ( index , ( i ) => {
102
+ if ( element . isEqualNode ( i . element ) ) {
103
+ return i ;
104
+ }
105
+ } ) ;
106
+
107
+ if ( group ) {
108
+ return group . card ;
109
+ }
110
+
111
+ return null ;
112
+ } ;
113
+
114
+ /**
115
+ * Remove an instance of Card from the stack index.
116
+ *
117
+ * @param {Card } card
118
+ * @returns {null }
119
+ */
120
+ stack . destroyCard = ( card ) => {
121
+ eventEmitter . trigger ( 'destroyCard' , card ) ;
122
+
123
+ return _ . remove ( index , {
124
+ card
125
+ } ) ;
126
+ } ;
127
+
128
+ return stack ;
129
129
} ;
130
130
131
131
export default Stack ;
0 commit comments