-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
51 lines (42 loc) · 1.65 KB
/
app.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
import deparam from 'can-deparam'
import route from 'can-route'
import startApp from './start-app'
import config from '~/src/config/'
import _isEmpty from 'lodash/isEmpty'
import _assign from 'lodash/assign'
import AppState from '~/src/models/app-state'
import Interview from '~/src/models/interview'
import MemoryState from '~/src/models/memory-state'
import PersistedState from '~/src/models/persisted-state'
import 'can-3-4-compat/dom-mutation-events'
import '~/src/mobile/util/helpers'
// !steal-remove-start
import debug from 'can-debug'
debug()
// !steal-remove-end
// State attrs not needing persistance, such as showing/hiding the table of contents.
// Load configuration from desktop into mobile
const qsParams = deparam(window.location.search.substring(1))
const mState = new MemoryState(_isEmpty(qsParams)
? config
: _assign({}, config, qsParams))
// AJAX request for interview json
const interviewPromise = Interview.findOne({
url: mState.attr('templateURL'),
resume: mState.attr('getDataURL')
})
// Local storage request for any existing answers
const persistedStatePromise = PersistedState.findOne()
// Route state
const appState = new AppState()
appState.connectedCallback(document.body)
route.register('view/{view}/page/{page}')
route.register('view/{view}/page/{page}/{repeatVarValue}')
route.register('view/{view}/page/{page}/{repeatVarValue}/{outerLoopVarValue}')
route.data = appState
const preventDefaultHandler = ev => ev.preventDefault()
$('body').on('click', 'a[href="#"]', preventDefaultHandler)
Promise.all([interviewPromise, persistedStatePromise])
.then(function ([interview, pState]) {
startApp({ interview, pState, mState, appState })
})