|
@@ -5,10 +5,24 @@
|
5
|
5
|
|
6
|
6
|
module rpgcards {
|
7
|
7
|
|
|
8
|
+ // Global objects, only accessible within this file
|
8
|
9
|
var appDispatcher: Dispatcher = null;
|
9
|
10
|
var appActions: Actions = null;
|
10
|
11
|
var appStore: Store = null;
|
11
|
12
|
|
|
13
|
+ // Access to the global objects, to be used from the browser debug window
|
|
14
|
+ export function debug() {
|
|
15
|
+ return {
|
|
16
|
+ dispatcher: appDispatcher,
|
|
17
|
+ actions: appActions,
|
|
18
|
+ store: appStore,
|
|
19
|
+ refresh: refresh,
|
|
20
|
+ testState: setupTestState
|
|
21
|
+ }
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ // Initializes the application
|
|
25
|
+ // Creates and links the global objects
|
12
|
26
|
export function bootstrap() {
|
13
|
27
|
appDispatcher = new Dispatcher();
|
14
|
28
|
appActions = new Actions(appDispatcher);
|
|
@@ -18,6 +32,9 @@ module rpgcards {
|
18
|
32
|
refresh();
|
19
|
33
|
}
|
20
|
34
|
|
|
35
|
+ // Renders the whole application
|
|
36
|
+ // In this project, render*() functions are pure functions that map
|
|
37
|
+ // the application state (Store) to React elements
|
21
|
38
|
function renderApp(store: Store) {
|
22
|
39
|
return React.DOM.div(
|
23
|
40
|
{},
|
|
@@ -26,8 +43,23 @@ module rpgcards {
|
26
|
43
|
);
|
27
|
44
|
}
|
28
|
45
|
|
29
|
|
- export function refresh() {
|
|
46
|
+ function refresh() {
|
30
|
47
|
React.render(renderApp(appStore), document.body);
|
31
|
48
|
}
|
32
|
49
|
|
|
50
|
+ function setupTestState() {
|
|
51
|
+ console.log(
|
|
52
|
+ "This function resets the current application state"
|
|
53
|
+ + " and then triggers a series of hardcoded user actions,"
|
|
54
|
+ + " in order to set up some application state that can be used"
|
|
55
|
+ + " for testing");
|
|
56
|
+ appActions.reset();
|
|
57
|
+ appActions.newDeck();
|
|
58
|
+ appStore.getDeckList().lift(deckIds => appActions.newCard(deckIds[0]));
|
|
59
|
+ appStore.getDeckList().lift(deckIds => appActions.newCard(deckIds[0]));
|
|
60
|
+ appActions.newDeck();
|
|
61
|
+ appStore.getDeckList().lift(deckIds => appActions.newCard(deckIds[1]));
|
|
62
|
+ appActions.newDeck();
|
|
63
|
+ }
|
|
64
|
+
|
33
|
65
|
}
|