Skip to content

Commit f46c608

Browse files
author
Guillaume Chau
committed
refactor: storage & shared data
1 parent 144a4e6 commit f46c608

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

src/devtools/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import './plugins'
77
import { parse } from '../util'
88
import { isChrome, initEnv } from './env'
99
import SharedData, { init as initSharedData, destroy as destroySharedData } from 'src/shared-data'
10-
import storage from './storage'
1110
import VuexResolve from './views/vuex/resolve'
1211

1312
for (const key in filters) {
@@ -100,7 +99,7 @@ function initApp (shell) {
10099
initSharedData({
101100
bridge,
102101
Vue,
103-
storage
102+
persist: true
104103
})
105104

106105
bridge.once('ready', version => {

src/devtools/views/events/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import storage from '../../storage'
1+
import storage from 'src/storage'
22
import { classify } from 'src/util'
33
import SharedData from 'src/shared-data'
44

src/devtools/views/router/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import storage from '../../storage'
1+
import storage from 'src/storage'
22

33
const ENABLED_KEY = 'EVENTS_ENABLED'
44
const enabled = storage.get(ENABLED_KEY)

src/devtools/views/routes/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import storage from '../../storage'
1+
import storage from 'src/storage'
22

33
const ENABLED_KEY = 'EVENTS_ENABLED'
44
const enabled = storage.get(ENABLED_KEY)

src/shared-data.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import storage from './storage'
2+
13
// Initial state
24
const internalSharedData = {
35
openInEditorHost: '/',
@@ -24,8 +26,6 @@ const persisted = [
2426

2527
let Vue
2628
let bridge
27-
// Storage API
28-
let storage = null
2929
// List of fields to persist to storage (disabled if 'false')
3030
// This should be unique to each shared data client to prevent conflicts
3131
let persist = false
@@ -36,23 +36,19 @@ export function init (params) {
3636
// Mandatory params
3737
bridge = params.bridge
3838
Vue = params.Vue
39-
40-
if (params.hasOwnProperty('storage')) {
41-
storage = params.storage
42-
persist = persisted
43-
}
39+
persist = !!params.persist
4440

4541
// Load persisted fields
46-
if (persist) {
47-
persist.forEach(key => {
48-
const value = storage.get(`shared-data:${key}`)
49-
if (value !== null) {
50-
internalSharedData[key] = value
51-
// Send to other shared data clients
42+
persisted.forEach(key => {
43+
const value = storage.get(`shared-data:${key}`)
44+
if (value !== null) {
45+
internalSharedData[key] = value
46+
// Send to other shared data clients
47+
if (persist) {
5248
sendValue(key, value)
5349
}
54-
})
55-
}
50+
}
51+
})
5652

5753
// Wrapper Vue instance
5854
vm = new Vue({
@@ -72,7 +68,7 @@ export function destroy () {
7268

7369
function setValue (key, value) {
7470
// Storage
75-
if (persist && persist.includes(key)) {
71+
if (persist && persisted.includes(key)) {
7672
storage.set(`shared-data:${key}`, value)
7773
}
7874
vm[key] = value
File renamed without changes.

0 commit comments

Comments
 (0)