-
Notifications
You must be signed in to change notification settings - Fork 383
/
playback.js
72 lines (69 loc) · 1.93 KB
/
playback.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
69
70
71
72
import {
PLAY,
PAUSE,
STOP,
STATUS,
SET_FRAMES,
APPEND_FRAMES,
FRAMES_LOADING,
SET_CURRENT_FRAME,
SELECT_PLAYBACK_RANGE,
CHANGE_SETTING,
UPDATE_METADATA
} from '../actions/playback';
import { RESET_CONTROLS } from '../actions/controls';
import { set } from '../utils/ImmutableUtils';
const DEFAULT_SETTINGS = {
timeStep: 1,
stepUnit: "days",
frameDuration: 2,
following: true
};
export default (state = { status: STATUS.STOP, currentFrame: -1, settings: DEFAULT_SETTINGS}, action) => {
switch (action.type) {
case PLAY: {
return set(`status`, STATUS.PLAY, state);
}
case PAUSE: {
return set(`status`, STATUS.PAUSE, state);
}
case STOP: {
return set(`status`, STATUS.STOP,
set('currentFrame', -1, state)
);
}
case SET_FRAMES: {
return set('frames', action.frames,
set('currentFrame', -1, state)
);
}
case FRAMES_LOADING: {
return set('framesLoading', action.loading, state);
}
case APPEND_FRAMES: {
return set('frames', [
...(state.frames || []),
...action.frames
], state);
}
case SET_CURRENT_FRAME: {
return set('currentFrame', action.frame, state);
}
case SELECT_PLAYBACK_RANGE: {
return set('playbackRange', action.range, state);
}
case CHANGE_SETTING: {
return set(`settings[${action.name}]`, action.value, state);
}
case UPDATE_METADATA: {
return set('metadata', { next: action.next, previous: action.previous, forTime: action.forTime}, state);
}
case RESET_CONTROLS: {
return set('metadata', undefined, set('framesLoading', undefined, set('playbackRange', undefined, set('frames', undefined,
set('currentFrame', -1, set('status', "STOP", set('settings', DEFAULT_SETTINGS, state)
))))));
}
default:
return state;
}
};