Skip to content

Commit

Permalink
Fix(Storage): Fix storage pannel sorting error when setting `storage.…
Browse files Browse the repository at this point in the history
…defaultStorages` option. (issue #560)
  • Loading branch information
Maizify committed Sep 21, 2022
1 parent 07a7596 commit 164857e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ English | [简体中文](./CHANGELOG_CN.md)
- `Fix(Log)` Fix `window.onerror` missing line breaks.
- `Fix(Log)` Fix unclickable `vc-cmd-clear-btn` on iOS Safari. (PR #564)
- `Fix(Log)` Fix a typo that misjudged circular reference objects. (issue #566)
- `Fix(Storage)` Fix storage pannel sorting error when setting `storage.defaultStorages` option. (issue #560)
- `Fix(Core)` Fix plugin panel sorting error when setting `pluginOrder` option. (issue #559)
- `Chore` Add option `env['no-core-js']` to disable core-js polyfill. (PR #562)

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- `Fix(Log)` 修复 `window.onerror` 丢失换行的问题。
- `Fix(Log)` 修复清除命令行按钮在 iOS Safari 中无法点击的问题。 (PR #564)
- `Fix(Log)` 修复一处误判循环引用对象的笔误。 (issue #566)
- `Fix(Storage)` 修复因设置 `storage.defaultStorages` 导致 Storage 面板排序错误的问题。 (issue #560)
- `Fix(Core)` 修复因设置 `pluginOrder` 导致插件面板排序错误的问题。 (issue #559)
- `Chore` 添加 `env['no-core-js']` 选项来停用构建时使用 core-js polyfill。 (PR #562)

Expand Down
7 changes: 6 additions & 1 deletion dev/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<a onclick="xssStorage()" href="javascript:;" class="weui_btn weui_btn_default">XSS</a>
<a onclick="defaultStoragesClear()" href="javascript:;" class="weui_btn weui_btn_default">defaultStorages: clear</a>
<a onclick="defaultStoragesAdd()" href="javascript:;" class="weui_btn weui_btn_default">defaultStorages: add</a>
<a onclick="defaultStoragesUpdate()" href="javascript:;" class="weui_btn weui_btn_default">defaultStorages: update</a>
</div>
</body>
</html>
Expand All @@ -28,7 +29,7 @@
window.vConsole = new window.VConsole({
// disableLogScrolling: true,
storage: {
// defaultStorages: [],
// defaultStorages: ['sessionStorage', 'cookies', 'localStorage'],
},
onReady: function() {
console.log('vConsole is ready.');
Expand Down Expand Up @@ -140,4 +141,8 @@
window.wx = {};
vConsole.setOption('storage.defaultStorages', ['wxStorage', 'localStorage']);
}

function defaultStoragesUpdate() {
vConsole.setOption('storage.defaultStorages', ['localStorage', 'unknownStorage', 'sessionStorage']);
}
</script>
14 changes: 10 additions & 4 deletions src/storage/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { get } from 'svelte/store';
import { isArray } from '../lib/tool';
import { VConsoleSveltePlugin } from '../lib/sveltePlugin';
import { VConsoleStorageModel, storageStore } from './storage.model';
import { default as StorageComp } from './storage.svelte';
Expand Down Expand Up @@ -53,9 +54,14 @@ export class VConsoleStoragePlugin extends VConsoleSveltePlugin {
}

public onUpdateOption() {
if (typeof this.vConsole.option.storage?.defaultStorages !== 'undefined') {
storageStore.defaultStorages.set(this.vConsole.option.storage?.defaultStorages || []);
this.updateTopBar();
let defaultStorages = this.vConsole.option.storage?.defaultStorages;
if (isArray(defaultStorages)) {
defaultStorages = defaultStorages.length > 0 ? defaultStorages : ['cookies'];
if (defaultStorages !== get(storageStore.defaultStorages)) {
storageStore.defaultStorages.set(defaultStorages);
storageStore.activedName.set(defaultStorages[0]);
this.updateTopBar();
}
}
}

Expand All @@ -73,7 +79,7 @@ export class VConsoleStoragePlugin extends VConsoleSveltePlugin {
data: {
name: name,
},
actived: i === 0,
actived: name === get(storageStore.activedName),
onClick: (e: PointerEvent, data: { name: string }) => {
const activedName = get(storageStore.activedName);
if (data.name === activedName) {
Expand Down

0 comments on commit 164857e

Please sign in to comment.