-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
152 lines (143 loc) · 3.55 KB
/
index.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>@veams/rx-store demo</title>
</head>
<body>
<div id="app">No data yet!
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.4/rxjs.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/4.0.5/redux.min.js"></script>
<script src="../lib-umd/index.js"></script>
<script>
let count = 0;
const el = document.getElementById('app');
const reduxStore = Redux.createStore(
Redux.combineReducers({
ui: (state = {}, action) => {
switch (action.type) {
default:
return state;
}
},
person: (state = {}, action) => {
switch (action.type) {
case 'person:add':
return {
...state,
entities: {
...state.entities,
...action.payload,
},
};
default:
return state;
}
},
}),
{
ui: {},
person: {
status: 'fetched',
entities: {},
},
}
);
const store = RxStore.createObservableFromRedux({
store: reduxStore,
});
const females$ = store
.select(state => state.person.entities)
.pipe(
rxjs.operators.map(items => {
return Object.values(items).filter(person => person.gender === 'female');
})
)
.subscribe(females => {
count += 1;
console.log('count: ', count);
el.innerHTML = `<pre>${JSON.stringify(females, null, 4)}</pre>`; // Prints [{name: "Adriana", gender: "female"}] and upcoming changes to the person slice
});
// Later on we want to unsubscribe
setTimeout(() => {
females$.unsubscribe();
}, 5000);
// DISPATCH ACTIONS
setTimeout(() => {
store.dispatch({
type: 'person:add',
payload: {
1: {
name: 'John',
gender: 'male',
},
2: {
name: 'Max',
gender: 'male',
},
3: {
name: 'Adriana',
gender: 'female',
},
},
});
}, 1000);
setTimeout(() => {
store.dispatch({
type: 'person:add',
payload: {
4: {
name: 'Andrea',
gender: 'female',
},
},
});
}, 2000);
setTimeout(() => {
store.dispatch({
type: 'person:add',
payload: {
4: {
name: 'Andreas',
gender: 'male',
},
},
});
}, 3000);
setTimeout(() => {
store.dispatch({
type: 'person:add',
payload: {
5: {
name: 'Maxime',
gender: 'female',
},
},
});
}, 4000);
setTimeout(() => {
store.dispatch({
type: 'person:add',
payload: {
5: {
name: 'Maxime',
gender: 'female',
},
},
});
}, 4500);
setTimeout(() => {
store.dispatch({
type: 'person:add',
payload: {
6: {
name: 'Sylvia',
gender: 'female',
},
},
});
}, 6000);
</script>
</body>
</html>