fix URLSearchParams in edge
This commit is contained in:
parent
9b316665b6
commit
bd77fb43c3
|
@ -1,25 +1,26 @@
|
|||
import noop from 'lodash/noop'
|
||||
import { thunk } from './thunk'
|
||||
|
||||
const enableMarks = process.browser &&
|
||||
// Lazily invoke because URLSearchParams isn't supported in Edge 16,
|
||||
// so we need the polyfill.
|
||||
const enabled = thunk(() => process.browser &&
|
||||
performance.mark &&
|
||||
(process.env.NODE_ENV !== 'production' ||
|
||||
new URLSearchParams(location.search).get('marks') === 'true')
|
||||
(
|
||||
process.env.NODE_ENV !== 'production' ||
|
||||
new URLSearchParams(location.search).get('marks') === 'true'
|
||||
)
|
||||
)
|
||||
|
||||
const perf = process.browser && performance
|
||||
|
||||
function doMark (name) {
|
||||
export function mark(name) {
|
||||
if (enabled()) {
|
||||
perf.mark(`start ${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
function doStop (name) {
|
||||
export function stop(name) {
|
||||
if (enabled()) {
|
||||
perf.mark(`end ${name}`)
|
||||
perf.measure(name, `start ${name}`, `end ${name}`)
|
||||
}
|
||||
|
||||
const mark = enableMarks ? doMark : noop
|
||||
const stop = enableMarks ? doStop : noop
|
||||
|
||||
export {
|
||||
mark,
|
||||
stop
|
||||
}
|
||||
}
|
11
routes/_utils/thunk.js
Normal file
11
routes/_utils/thunk.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
export function thunk(fn) {
|
||||
let value
|
||||
let called
|
||||
return () => {
|
||||
if (!called) {
|
||||
value = fn()
|
||||
called = true
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import '../routes/_utils/historyEvents'
|
|||
import '../routes/_utils/loadingMask'
|
||||
|
||||
loadPolyfills().then(() => {
|
||||
console.log('init()')
|
||||
// `routes` is an array of route objects injected by Sapper
|
||||
init(document.querySelector('#sapper'), __routes__)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue