Skip to content

Commit 07d9a45

Browse files
committed
better debugging, fix #3
1 parent 7cefcce commit 07d9a45

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tutorcruncher-socket",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"description": "TutorCruncher socket",
55
"author": "Samuel Colvin <[email protected]>",
66
"private": false,

src/main.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const ConfiguredVueRouter = config => {
6767
}
6868
)
6969
}
70+
console.debug('setting routes:', routes)
7071
return new VueRouter({
7172
mode: config.router_mode,
7273
routes: routes
@@ -101,6 +102,18 @@ module.exports = function (public_key, config) {
101102
config: config,
102103
})
103104

105+
if (!config.console) {
106+
config.console = console
107+
if (!window.localStorage.tcs_enable_debug) {
108+
if (!window.tcs_debug_log) {
109+
window.tcs_debug_log = []
110+
}
111+
console.debug = function () {
112+
window.tcs_debug_log.push(Array.from(arguments).join())
113+
}
114+
}
115+
}
116+
104117
let error = null
105118
if (!config.mode) {
106119
config.mode = 'grid'
@@ -132,10 +145,6 @@ module.exports = function (public_key, config) {
132145
config.router_mode = 'hash'
133146
}
134147

135-
if (!config.console) {
136-
config.console = console
137-
}
138-
139148
if (!config.element) {
140149
config.element = '#socket'
141150
}
@@ -163,6 +172,8 @@ module.exports = function (public_key, config) {
163172

164173
const ga_prefixes = init_ga(router, config)
165174

175+
console.debug('using config:', config)
176+
166177
const v = new Vue({
167178
el: config.element,
168179
router: router,
@@ -191,7 +202,8 @@ module.exports = function (public_key, config) {
191202
}
192203
},
193204
watch: {
194-
'$route' (to) {
205+
'$route' (to, from) {
206+
console.debug(`route change ${from.path} to ${to.path}`, from, to)
195207
if (this.config.mode === 'grid' && to.name === 'index') {
196208
this.get_contractor_list()
197209
}
@@ -209,9 +221,11 @@ module.exports = function (public_key, config) {
209221
},
210222
request (url, callback, expected_status, method, data) {
211223
const xhr = new window.XMLHttpRequest()
212-
xhr.open(method || 'GET', url)
224+
method = method || 'GET'
225+
xhr.open(method, url)
213226
xhr.setRequestHeader('Accept', 'application/json')
214227
xhr.onload = () => {
228+
console.debug(`request ${method} ${url} > ${xhr.status}`, data, xhr)
215229
try {
216230
if (xhr.status !== (expected_status || 200)) {
217231
throw Error(`bad response status ${xhr.status} not 200`)
@@ -326,6 +340,7 @@ ${xhr.responseText}`)
326340
ga_event (category, action, label) {
327341
/* istanbul ignore next */
328342
for (let prefix of ga_prefixes) {
343+
console.debug('ga sending event', prefix, category, action, label)
329344
window.ga(prefix + 'send', 'event', category, action, label)
330345
}
331346
},
@@ -357,7 +372,6 @@ ${xhr.responseText}`)
357372
}
358373

359374
window._tcs_grecaptcha_loaded = () => {
360-
console.log('_tcs_grecaptcha_loaded', window.socket_view)
361375
for (let v of window.socket_view) {
362376
v.render_grecaptcha()
363377
}

0 commit comments

Comments
 (0)