Skip to content

Commit

Permalink
fix(settings): settings should be stored and reused on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Apr 12, 2016
1 parent d9e6b75 commit dad2c8b
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,44 @@ module.exports = function Devtools () {
}

window.addEventListener('cerebral.dev.debuggerPing', function () {
var event = new CustomEvent('cerebral.dev.cerebralPong', {
detail: JSON.stringify({
type: 'init',
app: APP_ID,
version: VERSION,
data: getInit()
var signals = []

if (utils.hasLocalStorage()) {
disableDebugger = JSON.parse(localStorage.getItem('cerebral_disable_debugger'))
signals = JSON.parse(localStorage.getItem('cerebral_signals')) || []
willKeepState = JSON.parse(localStorage.getItem('cerebral_willKeepState'))
}

// Might be an async signal running here
if (willKeepState && signalStore.isExecutingAsync()) {
controller.once('signalEnd', function () {
signalStore.setSignals(signals)
signalStore.remember(signalStore.getSignals().length - 1)
isInitialized = true
var event = new CustomEvent('cerebral.dev.cerebralPong', {
detail: JSON.stringify({
type: 'init',
app: APP_ID,
version: VERSION,
data: getInit()
})
})
window.dispatchEvent(event)
})
})
window.dispatchEvent(event)
} else {
signalStore.setSignals(signals)
signalStore.rememberInitial(signalStore.getSignals().length - 1)
isInitialized = true
var event = new CustomEvent('cerebral.dev.cerebralPong', {
detail: JSON.stringify({
type: 'init',
app: APP_ID,
version: VERSION,
data: getInit()
})
})
window.dispatchEvent(event)
}
})

window.addEventListener('cerebral.dev.toggleKeepState', function () {
Expand Down

0 comments on commit dad2c8b

Please sign in to comment.