crobi преди 9 години
родител
ревизия
4424347a58
променени са 2 файла, в които са добавени 16 реда и са изтрити 1 реда
  1. 7
    0
      client/src/actions/actions.ts
  2. 9
    1
      client/src/stores/store.ts

+ 7
- 0
client/src/actions/actions.ts Целия файл

@@ -1,6 +1,10 @@
1 1
 /// <reference path="../dispatcher/dispatcher.ts"/>
2 2
 
3 3
 module rpgcards {
4
+    /* State actions */
5
+    export class ActionReset implements Action {
6
+        constructor() {}
7
+    }
4 8
 
5 9
     /* Deck actions */
6 10
     export class ActionNewDeck implements Action {
@@ -38,6 +42,9 @@ module rpgcards {
38 42
     export class Actions  {
39 43
         constructor(private _dispatcher: Dispatcher) {
40 44
         }
45
+        public reset(): void {
46
+            this._dispatcher.dispatch(new ActionReset());
47
+        }
41 48
         public newDeck(): void {
42 49
             this._dispatcher.dispatch(new ActionNewDeck());
43 50
         }

+ 9
- 1
client/src/stores/store.ts Целия файл

@@ -30,7 +30,9 @@ module rpgcards {
30 30
             this._selectedDeck = "";
31 31
 
32 32
             dispatcher.register((action) => {
33
-                if(action instanceof ActionNewDeck) {
33
+                if(action instanceof ActionReset) {
34
+                    this._reset()
35
+                } else if(action instanceof ActionNewDeck) {
34 36
                     this._newDeck()
35 37
                 } else if (action instanceof ActionDeleteDeck) {
36 38
                     this._deleteDeck(action.id);
@@ -86,6 +88,12 @@ module rpgcards {
86 88
         // ---------------------------------------------------------------------
87 89
         // Methods for changing the state
88 90
         // ---------------------------------------------------------------------
91
+        private _reset(): void {
92
+            this._decks = [];
93
+            this._cards = [];
94
+            this._selectDeck = null;
95
+            this._selectCard = null;
96
+        }
89 97
         private _newDeck(): void {
90 98
             this._decks.push(new Deck(randomID()));
91 99
         }

Loading…
Отказ
Запис