Merge branch 'setttingssync' into shigusegubu-themes3
This commit is contained in:
commit
10422b24a8
5 changed files with 66 additions and 66 deletions
|
|
@ -27,7 +27,6 @@ export default {
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue'],
|
emits: ['update:modelValue'],
|
||||||
data() {
|
data() {
|
||||||
console.log(this.fallback)
|
|
||||||
return {
|
return {
|
||||||
manualEntry: false,
|
manualEntry: false,
|
||||||
availableOptions: [
|
availableOptions: [
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,6 @@ const DEFAULT_STATE = {
|
||||||
...LOCAL_DEFAULT_CONFIG,
|
...LOCAL_DEFAULT_CONFIG,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
console.log('===', ROOT_STATE_DEFINITIONS)
|
|
||||||
|
|
||||||
export const useInstanceStore = defineStore('instance', {
|
export const useInstanceStore = defineStore('instance', {
|
||||||
state: () => ({ ...DEFAULT_STATE }),
|
state: () => ({ ...DEFAULT_STATE }),
|
||||||
|
|
|
||||||
|
|
@ -292,12 +292,15 @@ export const _mergePrefs = (recent, stale) => {
|
||||||
const totalJournal = _mergeJournal(staleJournal, recentJournal)
|
const totalJournal = _mergeJournal(staleJournal, recentJournal)
|
||||||
totalJournal
|
totalJournal
|
||||||
.filter(({ path, operation, args }) => {
|
.filter(({ path, operation, args }) => {
|
||||||
|
const entry = path.split('.')[1]
|
||||||
|
if (operation === 'unset') return ROOT_CONFIG[entry] !== undefined
|
||||||
|
|
||||||
const definition = path.startsWith('simple.muteFilters')
|
const definition = path.startsWith('simple.muteFilters')
|
||||||
? { default: {} }
|
? { default: {} }
|
||||||
: ROOT_CONFIG_DEFINITIONS[path.split('.')[1]]
|
: ROOT_CONFIG_DEFINITIONS[entry]
|
||||||
|
|
||||||
const finalValue = validateSetting({
|
const finalValue = validateSetting({
|
||||||
path: path.split('.')[1],
|
path: entry,
|
||||||
value: args[0],
|
value: args[0],
|
||||||
definition,
|
definition,
|
||||||
throwError: false,
|
throwError: false,
|
||||||
|
|
@ -768,7 +771,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
},
|
},
|
||||||
persist: {
|
persist: {
|
||||||
afterLoad(state) {
|
afterLoad(state) {
|
||||||
console.log('Validating persisted state of SyncConfig')
|
console.debug('Validating persisted state of SyncConfig')
|
||||||
const newState = { ...state }
|
const newState = { ...state }
|
||||||
const newEntries = Object.entries(newState.prefsStorage.simple).map(
|
const newEntries = Object.entries(newState.prefsStorage.simple).map(
|
||||||
([path, value]) => {
|
([path, value]) => {
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,6 @@ export const _mergeHighlights = (recent, stale) => {
|
||||||
if (!recent) return stale
|
if (!recent) return stale
|
||||||
const { _journal: recentJournal, ...recentHighlight } = recent
|
const { _journal: recentJournal, ...recentHighlight } = recent
|
||||||
const { _journal: staleJournal } = stale
|
const { _journal: staleJournal } = stale
|
||||||
console.log(recentHighlight)
|
|
||||||
/** Journal entry format:
|
/** Journal entry format:
|
||||||
* user: user to entry in highlight storage
|
* user: user to entry in highlight storage
|
||||||
* timestamp: timestamp of the change
|
* timestamp: timestamp of the change
|
||||||
|
|
@ -333,7 +332,6 @@ export const useUserHighlightStore = defineStore('user_highlight', {
|
||||||
if (stale && recent && !this.dirty) {
|
if (stale && recent && !this.dirty) {
|
||||||
this.cache._timestamp = Math.min(stale._timestamp, recent._timestamp)
|
this.cache._timestamp = Math.min(stale._timestamp, recent._timestamp)
|
||||||
}
|
}
|
||||||
console.log('CACHE', this.cache)
|
|
||||||
this.highlight = this.cache.highlight
|
this.highlight = this.cache.highlight
|
||||||
},
|
},
|
||||||
pushHighlight({ force = false } = {}) {
|
pushHighlight({ force = false } = {}) {
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ describe('The SyncConfig store', () => {
|
||||||
const largeJournal = []
|
const largeJournal = []
|
||||||
for (let value = 0; value < 1000; value++) {
|
for (let value = 0; value < 1000; value++) {
|
||||||
largeJournal.push({
|
largeJournal.push({
|
||||||
path: 'simple.testing' + value,
|
path: 'simple.palette' + value,
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: [value],
|
args: [value],
|
||||||
// should have A timestamp, we don't really care what it is
|
// should have A timestamp, we don't really care what it is
|
||||||
|
|
@ -171,13 +171,13 @@ describe('The SyncConfig store', () => {
|
||||||
store.pushSyncConfig = () => {
|
store.pushSyncConfig = () => {
|
||||||
/* no-op */
|
/* no-op */
|
||||||
}
|
}
|
||||||
store.setPreference({ path: 'simple.testing', value: 1 })
|
store.setPreference({ path: 'simple.palette', value: '1' })
|
||||||
expect(store.prefsStorage.simple.testing).to.eql(1)
|
expect(store.prefsStorage.simple.palette).to.eql('1')
|
||||||
expect(store.prefsStorage._journal.length).to.eql(1)
|
expect(store.prefsStorage._journal.length).to.eql(1)
|
||||||
expect(store.prefsStorage._journal[0]).to.eql({
|
expect(store.prefsStorage._journal[0]).to.eql({
|
||||||
path: 'simple.testing',
|
path: 'simple.palette',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: [1],
|
args: ['1'],
|
||||||
// should have A timestamp, we don't really care what it is
|
// should have A timestamp, we don't really care what it is
|
||||||
timestamp: store.prefsStorage._journal[0].timestamp,
|
timestamp: store.prefsStorage._journal[0].timestamp,
|
||||||
})
|
})
|
||||||
|
|
@ -189,26 +189,26 @@ describe('The SyncConfig store', () => {
|
||||||
store.pushSyncConfig = () => {
|
store.pushSyncConfig = () => {
|
||||||
/* no-op */
|
/* no-op */
|
||||||
}
|
}
|
||||||
store.setPreference({ path: 'simple.testing', value: 1 })
|
store.setPreference({ path: 'simple.palette', value: 1 })
|
||||||
store.setPreference({ path: 'simple.testing', value: 2 })
|
store.setPreference({ path: 'simple.palette', value: 2 })
|
||||||
store.addCollectionPreference({ path: 'collections.testing', value: 2 })
|
store.addCollectionPreference({ path: 'collections.palette', value: 2 })
|
||||||
store.removeCollectionPreference({
|
store.removeCollectionPreference({
|
||||||
path: 'collections.testing',
|
path: 'collections.palette',
|
||||||
value: 2,
|
value: 2,
|
||||||
})
|
})
|
||||||
store.updateCache({ username: 'test' })
|
store.updateCache({ username: 'test' })
|
||||||
expect(store.prefsStorage.simple.testing).to.eql(2)
|
expect(store.prefsStorage.simple.palette).to.eql(2)
|
||||||
expect(store.prefsStorage.collections.testing).to.eql([])
|
expect(store.prefsStorage.collections.palette).to.eql([])
|
||||||
expect(store.prefsStorage._journal.length).to.eql(2)
|
expect(store.prefsStorage._journal.length).to.eql(2)
|
||||||
expect(store.prefsStorage._journal[0]).to.eql({
|
expect(store.prefsStorage._journal[0]).to.eql({
|
||||||
path: 'simple.testing',
|
path: 'simple.palette',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: [2],
|
args: [2],
|
||||||
// should have A timestamp, we don't really care what it is
|
// should have A timestamp, we don't really care what it is
|
||||||
timestamp: store.prefsStorage._journal[0].timestamp,
|
timestamp: store.prefsStorage._journal[0].timestamp,
|
||||||
})
|
})
|
||||||
expect(store.prefsStorage._journal[1]).to.eql({
|
expect(store.prefsStorage._journal[1]).to.eql({
|
||||||
path: 'collections.testing',
|
path: 'collections.palette',
|
||||||
operation: 'removeFromCollection',
|
operation: 'removeFromCollection',
|
||||||
args: [2],
|
args: [2],
|
||||||
// should have A timestamp, we don't really care what it is
|
// should have A timestamp, we don't really care what it is
|
||||||
|
|
@ -222,13 +222,13 @@ describe('The SyncConfig store', () => {
|
||||||
store.pushSyncConfig = () => {
|
store.pushSyncConfig = () => {
|
||||||
/* no-op */
|
/* no-op */
|
||||||
}
|
}
|
||||||
store.setPreference({ path: 'simple.testing', value: 1 })
|
store.setPreference({ path: 'simple.palette', value: 1 })
|
||||||
store.setPreference({ path: 'simple.testing', value: 1 })
|
store.setPreference({ path: 'simple.palette', value: 1 })
|
||||||
store.addCollectionPreference({ path: 'collections.testing', value: 2 })
|
store.addCollectionPreference({ path: 'collections.palette', value: 2 })
|
||||||
store.addCollectionPreference({ path: 'collections.testing', value: 2 })
|
store.addCollectionPreference({ path: 'collections.palette', value: 2 })
|
||||||
store.updateCache({ username: 'test' })
|
store.updateCache({ username: 'test' })
|
||||||
expect(store.prefsStorage.simple.testing).to.eql(1)
|
expect(store.prefsStorage.simple.palette).to.eql(1)
|
||||||
expect(store.prefsStorage.collections.testing).to.eql([2])
|
expect(store.prefsStorage.collections.palette).to.eql([2])
|
||||||
expect(store.prefsStorage._journal.length).to.eql(2)
|
expect(store.prefsStorage._journal.length).to.eql(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -238,10 +238,10 @@ describe('The SyncConfig store', () => {
|
||||||
store.pushSyncConfig = () => {
|
store.pushSyncConfig = () => {
|
||||||
/* no-op */
|
/* no-op */
|
||||||
}
|
}
|
||||||
store.setPreference({ path: 'simple.object.foo', value: 1 })
|
store.setPreference({ path: 'simple.fontInput.family', value: 'test' })
|
||||||
store.unsetPreference({ path: 'simple.object.foo' })
|
store.unsetPreference({ path: 'simple.fontInput.family' })
|
||||||
store.updateCache(store, { username: 'test' })
|
store.updateCache(store, { username: 'test' })
|
||||||
expect(store.prefsStorage.simple.object).to.not.have.property('foo')
|
expect(store.prefsStorage.simple.fontInput).to.not.have.property('family')
|
||||||
expect(store.prefsStorage._journal.length).to.eql(1)
|
expect(store.prefsStorage._journal.length).to.eql(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -393,11 +393,11 @@ describe('The SyncConfig store', () => {
|
||||||
_mergePrefs(
|
_mergePrefs(
|
||||||
// RECENT
|
// RECENT
|
||||||
{
|
{
|
||||||
simple: { a: 1, b: 0, c: true },
|
simple: { theme: '1', style: '0', hideISP: true },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.b', operation: 'set', args: [0], timestamp: 2 },
|
{ path: 'simple.style', operation: 'set', args: ['0'], timestamp: 2 },
|
||||||
{
|
{
|
||||||
path: 'simple.c',
|
path: 'simple.hideISP',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: [true],
|
args: [true],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
@ -406,19 +406,19 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
// STALE
|
// STALE
|
||||||
{
|
{
|
||||||
simple: { a: 1, b: 1, c: false },
|
simple: { theme: '1', style: '1', hideISP: false },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.a', operation: 'set', args: [1], timestamp: 1 },
|
{ path: 'simple.theme', operation: 'set', args: ['1'], timestamp: 1 },
|
||||||
{ path: 'simple.b', operation: 'set', args: [1], timestamp: 3 },
|
{ path: 'simple.style', operation: 'set', args: ['1'], timestamp: 3 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).to.eql({
|
).to.eql({
|
||||||
simple: { a: 1, b: 1, c: true },
|
simple: { theme: '1', style: '1', hideISP: true },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.a', operation: 'set', args: [1], timestamp: 1 },
|
{ path: 'simple.theme', operation: 'set', args: ['1'], timestamp: 1 },
|
||||||
{ path: 'simple.b', operation: 'set', args: [1], timestamp: 3 },
|
{ path: 'simple.style', operation: 'set', args: ['1'], timestamp: 3 },
|
||||||
{ path: 'simple.c', operation: 'set', args: [true], timestamp: 4 },
|
{ path: 'simple.hideISP', operation: 'set', args: [true], timestamp: 4 },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -428,11 +428,11 @@ describe('The SyncConfig store', () => {
|
||||||
_mergePrefs(
|
_mergePrefs(
|
||||||
// RECENT
|
// RECENT
|
||||||
{
|
{
|
||||||
simple: { a: 1, b: 0, c: false },
|
simple: { theme: '1', style: '0', hideISP: false },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.b', operation: 'set', args: [0], timestamp: 2 },
|
{ path: 'simple.style', operation: 'set', args: ['0'], timestamp: 2 },
|
||||||
{
|
{
|
||||||
path: 'simple.c',
|
path: 'simple.hideISP',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: [false],
|
args: [false],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
@ -441,19 +441,20 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
// STALE
|
// STALE
|
||||||
{
|
{
|
||||||
simple: { a: 0, b: 0, c: true },
|
simple: { theme: '0', style: '0', hideISP: true },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.a', operation: 'set', args: [0], timestamp: 1 },
|
{ path: 'simple.theme', operation: 'set', args: ['0'], timestamp: 1 },
|
||||||
{ path: 'simple.b', operation: 'set', args: [0], timestamp: 3 },
|
{ path: 'simple.style', operation: 'set', args: ['0'], timestamp: 3 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).to.eql({
|
).to.eql({
|
||||||
simple: { a: 0, b: 0, c: false },
|
simple: { a: 0, b: 0, c: false },
|
||||||
|
simple: { theme: '0', style: '0', hideISP: false },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.a', operation: 'set', args: [0], timestamp: 1 },
|
{ path: 'simple.theme', operation: 'set', args: ['0'], timestamp: 1 },
|
||||||
{ path: 'simple.b', operation: 'set', args: [0], timestamp: 3 },
|
{ path: 'simple.style', operation: 'set', args: ['0'], timestamp: 3 },
|
||||||
{ path: 'simple.c', operation: 'set', args: [false], timestamp: 4 },
|
{ path: 'simple.hideISP', operation: 'set', args: [false], timestamp: 4 },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -463,10 +464,10 @@ describe('The SyncConfig store', () => {
|
||||||
_mergePrefs(
|
_mergePrefs(
|
||||||
// RECENT
|
// RECENT
|
||||||
{
|
{
|
||||||
simple: { a: 'foo' },
|
simple: { theme: 'foo' },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.a',
|
path: 'simple.theme',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: ['foo'],
|
args: ['foo'],
|
||||||
timestamp: 2,
|
timestamp: 2,
|
||||||
|
|
@ -475,10 +476,10 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
// STALE
|
// STALE
|
||||||
{
|
{
|
||||||
simple: { a: 'bar' },
|
simple: { theme: 'bar' },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.a',
|
path: 'simple.theme',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: ['bar'],
|
args: ['bar'],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
@ -487,9 +488,9 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).to.eql({
|
).to.eql({
|
||||||
simple: { a: 'bar' },
|
simple: { theme: 'bar' },
|
||||||
_journal: [
|
_journal: [
|
||||||
{ path: 'simple.a', operation: 'set', args: ['bar'], timestamp: 4 },
|
{ path: 'simple.theme', operation: 'set', args: ['bar'], timestamp: 4 },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -499,10 +500,10 @@ describe('The SyncConfig store', () => {
|
||||||
_mergePrefs(
|
_mergePrefs(
|
||||||
// RECENT
|
// RECENT
|
||||||
{
|
{
|
||||||
simple: { lv2: { lv3: 'foo' } },
|
simple: { fontInput: { lv3: 'foo' } },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.lv2.lv3',
|
path: 'simple.fontInput.lv3',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: ['foo'],
|
args: ['foo'],
|
||||||
timestamp: 2,
|
timestamp: 2,
|
||||||
|
|
@ -511,10 +512,10 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
// STALE
|
// STALE
|
||||||
{
|
{
|
||||||
simple: { lv2: { lv3: 'bar' } },
|
simple: { fontInput: { lv3: 'bar' } },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.lv2.lv3',
|
path: 'simple.fontInput.lv3',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: ['bar'],
|
args: ['bar'],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
@ -523,10 +524,10 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).to.eql({
|
).to.eql({
|
||||||
simple: { lv2: { lv3: 'bar' } },
|
simple: { fontInput: { lv3: 'bar' } },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.lv2.lv3',
|
path: 'simple.fontInput.lv3',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: ['bar'],
|
args: ['bar'],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
@ -540,10 +541,10 @@ describe('The SyncConfig store', () => {
|
||||||
_mergePrefs(
|
_mergePrefs(
|
||||||
// RECENT
|
// RECENT
|
||||||
{
|
{
|
||||||
simple: { lv2: { lv3: 'foo' } },
|
simple: { fontInput: { lv3: 'foo' } },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.lv2.lv3',
|
path: 'simple.fontInput.lv3',
|
||||||
operation: 'set',
|
operation: 'set',
|
||||||
args: ['foo'],
|
args: ['foo'],
|
||||||
timestamp: 2,
|
timestamp: 2,
|
||||||
|
|
@ -552,10 +553,10 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
// STALE
|
// STALE
|
||||||
{
|
{
|
||||||
simple: { lv2: {} },
|
simple: { fontInput: {} },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.lv2.lv3',
|
path: 'simple.fontInput.lv3',
|
||||||
operation: 'unset',
|
operation: 'unset',
|
||||||
args: [],
|
args: [],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
@ -564,10 +565,10 @@ describe('The SyncConfig store', () => {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).to.eql({
|
).to.eql({
|
||||||
simple: { lv2: {} },
|
simple: { fontInput: {} },
|
||||||
_journal: [
|
_journal: [
|
||||||
{
|
{
|
||||||
path: 'simple.lv2.lv3',
|
path: 'simple.fontInput.lv3',
|
||||||
operation: 'unset',
|
operation: 'unset',
|
||||||
args: [],
|
args: [],
|
||||||
timestamp: 4,
|
timestamp: 4,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue