forked from jlfwong/speedscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication-container.tsx
63 lines (58 loc) · 2.36 KB
/
application-container.tsx
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
import {createContainer, Dispatch, bindActionCreator, ActionCreator} from '../lib/typed-redux'
import {Application, ActiveProfileState} from './application'
import {ApplicationState} from '../store'
import {getProfileToView, getCanvasContext} from '../store/getters'
import {actions} from '../store/actions'
import {Graphics} from '../gl/graphics'
export const ApplicationContainer = createContainer(
Application,
(state: ApplicationState, dispatch: Dispatch) => {
const {flattenRecursion, profileGroup} = state
let activeProfileState: ActiveProfileState | null = null
if (profileGroup) {
if (profileGroup.profiles.length > profileGroup.indexToView) {
const index = profileGroup.indexToView
const profileState = profileGroup.profiles[index]
activeProfileState = {
...profileGroup.profiles[profileGroup.indexToView],
profile: getProfileToView({profile: profileState.profile, flattenRecursion}),
index: profileGroup.indexToView,
}
}
}
function wrapActionCreator<T>(actionCreator: ActionCreator<T>): (t: T) => void {
return bindActionCreator(dispatch, actionCreator)
}
// TODO(jlfwong): Cache this and resizeCanvas below to prevent re-renders
// due to changing props.
const setters = {
setGLCanvas: wrapActionCreator(actions.setGLCanvas),
setLoading: wrapActionCreator(actions.setLoading),
setError: wrapActionCreator(actions.setError),
setProfileGroup: wrapActionCreator(actions.setProfileGroup),
setDragActive: wrapActionCreator(actions.setDragActive),
setViewMode: wrapActionCreator(actions.setViewMode),
setFlattenRecursion: wrapActionCreator(actions.setFlattenRecursion),
setProfileIndexToView: wrapActionCreator(actions.setProfileIndexToView),
}
return {
activeProfileState,
dispatch,
canvasContext: state.glCanvas ? getCanvasContext(state.glCanvas) : null,
resizeCanvas: (
widthInPixels: number,
heightInPixels: number,
widthInAppUnits: number,
heightInAppUnits: number,
) => {
if (state.glCanvas) {
const gl = getCanvasContext(state.glCanvas).gl
gl.resize(widthInPixels, heightInPixels, widthInAppUnits, heightInAppUnits)
gl.clear(new Graphics.Color(1, 1, 1, 1))
}
},
...setters,
...state,
}
},
)