Skip to content

Commit

Permalink
Merge pull request #12 from cerebral/multiApp
Browse files Browse the repository at this point in the history
feat(multiApp): support handling multiple apps
  • Loading branch information
christianalfoni committed Apr 10, 2016
2 parents 57971df + 38b28e0 commit 8894c03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 51 deletions.
60 changes: 10 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function Devtools () {
var disableDebugger = false
var willKeepState = false
var APP_ID = String(Date.now())
var VERSION = 'v2'
var VERSION = 'v3'
var isAwaitingFrame = false
var nextSignalInLine = 0

Expand Down Expand Up @@ -117,10 +117,6 @@ module.exports = function Devtools () {
}
}

var updateInit = function () {
update('init', getInit())
}

var updateSignals = function () {
if (isAwaitingFrame) {
return
Expand Down Expand Up @@ -149,52 +145,16 @@ module.exports = function Devtools () {
}, true)
}

var initialize = function () {
if (isInitialized) {
updateInit()
}
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'))
}

isInitialized = true

// Might be an async signal running here
if (willKeepState && signalStore.isExecutingAsync()) {
controller.once('signalEnd', function () {
signalStore.setSignals(signals)
signalStore.remember(signalStore.getSignals().length - 1)
var event = new CustomEvent('cerebral.dev.cerebralPong', {
detail: JSON.stringify({
type: 'init',
app: APP_ID,
version: VERSION,
data: getInit()
})
})
window.dispatchEvent(event)
})
} else {
signalStore.setSignals(signals)
signalStore.rememberInitial(signalStore.getSignals().length - 1)
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.debuggerPing', function () {
initialize()
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"cerebral": "^0.33.8"
},
"dependencies": {
"cerebral-module-signal-store": "^0.1.3"
"cerebral-module-signal-store": "^0.1.5"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit 8894c03

Please sign in to comment.