Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(multiApp): support handling multiple apps #12

Merged
merged 2 commits into from
Apr 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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