-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
44 lines (26 loc) · 1023 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {NumberReducer} from './reducer';
import {RxStore} from './rx-store';
import {AppState} from './interfaces';
import {Store} from './store';
//THE NON-REACTIVE STORY
let store = new Store<AppState>(NumberReducer, {counter:10});
//console.log(store.getState().counter);
let unsubscribe = store.subscribe(() => {
console.log('non-reactive subscription : ' + store.getState().counter);
})
store.dispatch({ type: 'INCREMENT' });
store.dispatch({ type: 'DECREMENT' });
store.dispatch({ type: 'PLUS', payload: 7 });
unsubscribe();
store.dispatch({ type: 'PLUS', payload: 7 });
console.log(store.getState());
//THE REACTIVE STORY
let rxStore = new RxStore<AppState>(NumberReducer, {counter:100});
//console.log(rxStore.getState());
rxStore.subscribe(() => {
console.log('reactive subscription : ' + rxStore.getState().counter);
})
rxStore.dispatch({ type: 'INCREMENT' });
rxStore.dispatch({ type: 'DECREMENT' });
rxStore.dispatch({ type: 'PLUS', payload: 7 });
console.log(rxStore.getState().counter);