@@ -9,6 +9,9 @@ interface SlotConfigurations {
9
9
onSpinStart ?: ( ) => void ;
10
10
/** User configuration for callback function that runs after spinning reel */
11
11
onSpinEnd ?: ( ) => void ;
12
+
13
+ /** User configuration for callback function that runs after user updates the name list */
14
+ onNameListChanged ?: ( ) => void ;
12
15
}
13
16
14
17
// commitStyles() is not yet supported by TypeScript
@@ -39,21 +42,25 @@ export default class Slot {
39
42
/** Callback function that runs after spinning reel */
40
43
private onSpinEnd ?: NonNullable < SlotConfigurations [ 'onSpinEnd' ] > ;
41
44
45
+ /** Callback function that runs after spinning reel */
46
+ private onNameListChanged ?: NonNullable < SlotConfigurations [ 'onNameListChanged' ] > ;
47
+
42
48
/**
43
49
* Constructor of Slot
44
50
* @param maxReelItems Maximum item inside a reel
45
51
* @param removeWinner Whether winner should be removed from name list
46
52
* @param reelContainerSelector The element ID of reel items to be appended
47
53
* @param onSpinStart Callback function that runs before spinning reel
48
- * @param onSpinEnd Callback function that runs after spinning reel
54
+ * @param onNameListChanged Callback function that runs when user updates the name list
49
55
*/
50
56
constructor (
51
57
{
52
58
maxReelItems = 30 ,
53
59
removeWinner = true ,
54
60
reelContainerSelector,
55
61
onSpinStart,
56
- onSpinEnd
62
+ onSpinEnd,
63
+ onNameListChanged
57
64
} : SlotConfigurations
58
65
) {
59
66
this . nameList = [ ] ;
@@ -62,6 +69,7 @@ export default class Slot {
62
69
this . shouldRemoveWinner = removeWinner ;
63
70
this . onSpinStart = onSpinStart ;
64
71
this . onSpinEnd = onSpinEnd ;
72
+ this . onNameListChanged = onNameListChanged ;
65
73
66
74
// Create reel animation
67
75
this . reelAnimation = this . reelContainer ?. animate (
@@ -93,6 +101,17 @@ export default class Slot {
93
101
*/
94
102
set names ( names : string [ ] ) {
95
103
this . nameList = names ;
104
+
105
+ const reelItemsToRemove = this . reelContainer ?. children
106
+ ? Array . from ( this . reelContainer . children )
107
+ : [ ] ;
108
+
109
+ reelItemsToRemove
110
+ . forEach ( ( element ) => element . remove ( ) ) ;
111
+
112
+ if ( this . onNameListChanged ) {
113
+ this . onNameListChanged ( ) ;
114
+ }
96
115
}
97
116
98
117
/** Getter for name list */
0 commit comments