瀏覽代碼

Reset state action

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

+ 9
- 1
client/src/stores/store.ts 查看文件

30
             this._selectedDeck = "";
30
             this._selectedDeck = "";
31
 
31
 
32
             dispatcher.register((action) => {
32
             dispatcher.register((action) => {
33
-                if(action instanceof ActionNewDeck) {
33
+                if(action instanceof ActionReset) {
34
+                    this._reset()
35
+                } else if(action instanceof ActionNewDeck) {
34
                     this._newDeck()
36
                     this._newDeck()
35
                 } else if (action instanceof ActionDeleteDeck) {
37
                 } else if (action instanceof ActionDeleteDeck) {
36
                     this._deleteDeck(action.id);
38
                     this._deleteDeck(action.id);
86
         // ---------------------------------------------------------------------
88
         // ---------------------------------------------------------------------
87
         // Methods for changing the state
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
         private _newDeck(): void {
97
         private _newDeck(): void {
90
             this._decks.push(new Deck(randomID()));
98
             this._decks.push(new Deck(randomID()));
91
         }
99
         }

Loading…
取消
儲存