iot-dashboard
Version:
A generic dashboard application based on JavaScript, HTML and CSS. http://iot-dashboard.org
228 lines (227 loc) • 7.86 kB
HTML
<html lang="en">
<head>
<title>Code coverage report for src/util/reducer.js</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="../../prettify.css" />
<link rel="stylesheet" href="../../base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(../../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="../../index.html">all files</a> / <a href="index.html">src/util/</a> reducer.js
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">87.5% </span>
<span class="quiet">Statements</span>
<span class='fraction'>21/24</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">81.82% </span>
<span class="quiet">Branches</span>
<span class='fraction'>9/11</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>2/2</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">86.96% </span>
<span class="quiet">Lines</span>
<span class='fraction'>20/23</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">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</td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-yes">215×</span>
<span class="cline-any cline-yes">215×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">12×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">202×</span>
<span class="cline-any cline-yes">120×</span>
<span class="cline-any cline-yes">82×</span>
<span class="cline-any cline-yes">82×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">76×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">6×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Creates an reducer that works on an object where you can create, delete and update properties of type Object.
* The key of properties always matches the id property of the value object.
*
* @param actionNames
* Object with: create, update, delete action names
* @param elementReducer
* A reducer for a single object that supports the actionNames.create and actionNames.update action.
* @param initialState (optional)
* @param idProperty
* The name of the property to fetch the id from the action. Default: 'id'
* @returns {crudReducer}
*/
function genCrudReducer(actionNames, elementReducer, idProperty) {
<span class="missing-if-branch" title="else path not taken" >E</span>if (idProperty === void 0) { idProperty = 'id'; }
console.assert(actionNames.length === 2, "ActionNames must contain 2 names for create, delete in that order");
var CREATE_ACTION = actionNames[0], DELETE_ACTION = actionNames[1];
return function crudReducer(state, action) {
var id = action[idProperty];
switch (action.type) {
case CREATE_ACTION:
return Object.assign({}, state, (_a = {}, _a[id] = elementReducer(undefined, action), _a));
case DELETE_ACTION:
var newState = Object.assign({}, state);
delete newState[id];
return newState;
default:
if (id === undefined)
return state;
var elementState = state[id];
if (elementState == undefined) {
// Do not update what we don't have.
// TODO: Log warning, or document why not.
return state;
}
var updatedElement = elementReducer(elementState, action);
<span class="missing-if-branch" title="if path not taken" >I</span>if (updatedElement == undefined) {
<span class="cstat-no" title="statement not covered" > console.error("ElementReducer has some problem: ", elementReducer, " with action: ", action);</span>
<span class="cstat-no" title="statement not covered" > throw new Error("Reducer must return the original state if they not implement the action. Check action " + action.type + ".");</span>
}
return Object.assign({}, state, (_b = {},
_b[id] = updatedElement,
_b
));
}
<span class="cstat-no" title="statement not covered" > var _a, _b;</span>
};
}
exports.genCrudReducer = genCrudReducer;
</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Nov 04 2016 11:23:08 GMT+0000 (UTC)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>