Skip to content

Sync 'classifyComponents' settings with backend #533

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

Merged
merged 2 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions src/backend/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export let claissifyComponents = false

export default function (bridge) {
bridge.on('config:classifyComponents', value => {
claissifyComponents = value
})
}
6 changes: 4 additions & 2 deletions src/backend/highlighter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inDoc } from '../util'
import { inDoc, classify } from '../util'
import { getInstanceName } from './index'
import { claissifyComponents } from './config'

const overlay = document.createElement('div')
overlay.style.backgroundColor = 'rgba(104, 182, 255, 0.35)'
Expand Down Expand Up @@ -30,7 +31,8 @@ export function highlight (instance) {
const rect = getInstanceRect(instance)
if (rect) {
let content = ''
const name = getInstanceName(instance)
let name = getInstanceName(instance)
claissifyComponents && (name = classify(name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there so many condition && statement instead of if (condition) statement 😆 I think we should stop adding more of those

name && (content = `<span style="opacity: .6;">&lt;</span>${name}<span style="opacity: .6;">&gt;</span>`)
showOverlay(rect, content)
}
Expand Down
3 changes: 3 additions & 0 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { initEventsBackend } from './events'
import { stringify, classify, camelize, set, parse } from '../util'
import path from 'path'
import ComponentSelector from './component-selector'
import config from './config'

// Use a custom basename functions instead of the shimed version
// because it doesn't work on Windows
Expand Down Expand Up @@ -39,6 +40,8 @@ export function initBackend (_bridge) {
} else {
hook.once('init', connect)
}

bridge && config(bridge)
Copy link
Member

@posva posva Jan 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when do you finnd yourself with no bridge?

}

function connect () {
Expand Down
2 changes: 2 additions & 0 deletions src/devtools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ function initApp (shell) {
}
}
}).$mount('#app')

store.dispatch('init')
})
}

Expand Down
7 changes: 7 additions & 0 deletions src/devtools/views/components/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ const mutations = {
}

const actions = {
init: {
handler ({ state }) {
bridge.send('config:classifyComponents', state.classifyComponents)
},
root: true
},
toggleInstance ({ commit, dispatch, state }, { instance, expanded, recursive, parent = false } = {}) {
const id = instance.id

Expand Down Expand Up @@ -98,6 +104,7 @@ const actions = {
const newValue = !state.classifyComponents
commit('CLASSIFY_COMPONENTS', newValue)
storage.set(CLASSIFY_COMPONENTS_KEY, newValue)
bridge.send('config:classifyComponents', newValue)
}
}

Expand Down