-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
125 lines (112 loc) · 4.35 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
<!DOCTYPE html>
<html>
<head>
<title>Redux basic example</title>
<script src="node_modules/redux/dist/redux.js"></script>
<script>
// FullStory snippet: https://help.fullstory.com/using/recording-snippet
window['_fs_debug'] = false;
window['_fs_host'] = 'fullstory.com';
window['_fs_org'] = 'YOUR ORG ID HERE'; // replace this with your OrgId
window['_fs_namespace'] = 'FS';
(function(m,n,e,t,l,o,g,y){
if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}
g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[];
o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js';
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)};
g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)};
g.consent=function(a){g("consent",!arguments.length||a)};
g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};
g.clearUserCookie=function(){};
})(window,document,window['_fs_namespace'],'script','user');
</script>
</head>
<body>
<h3>Borrowed from <a href="https://github.com/reduxjs/redux/tree/master/examples/counter-vanilla">https://github.com/reduxjs/redux/tree/master/examples/counter-vanilla</a></h3>
<div>
<p>
Clicked: <span id="value">0</span> times
<button id="increment">+</button>
<button id="decrement">-</button>
<button id="incrementIfOdd">Increment if odd</button>
<button id="incrementAsync">Increment async</button>
</p>
<button id="boom">BOOM!</button>
</div>
<script>
// example error
function boom() {
var thisIsaReferenceError = e;
}
// Redux reducer
function counter(state, action) {
if (typeof state === 'undefined') {
return 0;
}
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
case 'BOOM':
boom();
default:
return state;
}
}
// Middleware for capturing errors from https://redux.js.org/advanced/middleware#the-final-approach
const crashReporter = store => next => action => {
try {
return next(action);
} catch (err) {
// FullStory custom event
// https://help.fullstory.com/develop-js/363565-fs-event-api-sending-custom-event-data-into-fullstory
FS.event('Redux error', {
error: {
name: err.name,
message: err.message,
fileName: err.fileName,
lineNumber: err.lineNumber,
stack: err.stack,
},
counter: store.getState(), //NOTE: strip out any sensitive fields first
});
throw err;
}
};
// apply middleware when creating store
const store = Redux.createStore(counter, Redux.applyMiddleware(crashReporter));
const valueEl = document.getElementById('value');
function render() {
valueEl.innerHTML = store.getState().toString();
}
render();
store.subscribe(render);
document.getElementById('increment')
.addEventListener('click', function () {
store.dispatch({ type: 'INCREMENT' });
});
document.getElementById('decrement')
.addEventListener('click', function () {
store.dispatch({ type: 'DECREMENT' });
});
document.getElementById('incrementIfOdd')
.addEventListener('click', function () {
if (store.getState() % 2 !== 0) {
store.dispatch({ type: 'INCREMENT' });
}
});
document.getElementById('incrementAsync')
.addEventListener('click', function () {
setTimeout(function () {
store.dispatch({ type: 'INCREMENT' });
}, 1000);
});
document.getElementById('boom')
.addEventListener('click', () => {
store.dispatch({ type: 'BOOM' });
});
</script>
</body>
</html>