mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 19:56:02 +00:00
handle JSON in text cells
This commit is contained in:
@@ -2,9 +2,9 @@ import { writable, derived, readable } from 'svelte/store';
|
||||
import { ExtensionsDirectory } from 'dbgate-types';
|
||||
import invalidateCommands from './commands/invalidateCommands';
|
||||
import getElectron from './utility/getElectron';
|
||||
import { GlobalCommand } from './commands/registerCommand';
|
||||
import { useConfig, useSettings } from './utility/metadataLoaders';
|
||||
import _ from 'lodash';
|
||||
import { safeJsonParse } from 'dbgate-tools';
|
||||
|
||||
export interface TabDefinition {
|
||||
title: string;
|
||||
@@ -18,18 +18,9 @@ export interface TabDefinition {
|
||||
tabOrder?: number;
|
||||
}
|
||||
|
||||
function safeJsonParse(json, defaultValue) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch (err) {
|
||||
console.error(`Error parsing JSON value "${json}"`, err);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function writableWithStorage<T>(defaultValue: T, storageName) {
|
||||
const init = localStorage.getItem(storageName);
|
||||
const res = writable<T>(init ? safeJsonParse(init, defaultValue) : defaultValue);
|
||||
const res = writable<T>(init ? safeJsonParse(init, defaultValue, true) : defaultValue);
|
||||
res.subscribe(value => {
|
||||
localStorage.setItem(storageName, JSON.stringify(value));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user