-
Notifications
You must be signed in to change notification settings - Fork 383
/
snapshot.js
68 lines (63 loc) · 1.63 KB
/
snapshot.js
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
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
CHANGE_SNAPSHOT_STATE,
SNAPSHOT_ERROR,
SNAPSHOT_READY,
SNAPSHOT_ADD_QUEUE,
SNAPSHOT_REMOVE_QUEUE
} from '../actions/snapshot';
import assign from 'object-assign';
function snapshot(state = null, action) {
switch (action.type) {
case CHANGE_SNAPSHOT_STATE:
return assign({}, state, {
state: action.state,
tainted: action.tainted
});
case SNAPSHOT_READY:
return assign({}, state, {
img: {
data: action.imgData,
width: action.width,
height: action.height,
size: action.size
}
});
case SNAPSHOT_ERROR:
return assign({}, state, {
error: action.error
});
case SNAPSHOT_ADD_QUEUE: {
let queue = [];
if (state && state.queue !== undefined) {
queue = [...state.queue, action.options];
} else {
queue = [action.options];
}
return assign({}, state, {
queue: queue
});
}
case SNAPSHOT_REMOVE_QUEUE: {
let queue = state.queue || [];
queue = queue.filter((conf) => {
if (conf.key === action.options.key) {
return false;
}
return true;
});
return assign({}, state, {
queue: queue
});
}
default:
return state;
}
}
export default snapshot;