mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-04-04 03:21:03 +00:00
37 lines
842 B
JavaScript
37 lines
842 B
JavaScript
import { UpdateViewStore, Views } from '$wails/go/app/App';
|
|
import { get, writable } from 'svelte/store';
|
|
|
|
const { set, subscribe } = writable({});
|
|
let skipUpdate = true;
|
|
|
|
async function reload() {
|
|
const newViewStore = await Views();
|
|
set(newViewStore);
|
|
return newViewStore;
|
|
}
|
|
|
|
function forCollection(hostKey, dbKey, collKey) {
|
|
const allViews = get({ subscribe });
|
|
const entries = Object.entries(allViews).filter(v => (
|
|
v[0] === 'list' || (
|
|
v[1].host === hostKey &&
|
|
v[1].database === dbKey &&
|
|
v[1].collection === collKey
|
|
)
|
|
));
|
|
|
|
return Object.fromEntries(entries);
|
|
}
|
|
|
|
reload();
|
|
subscribe(newViewStore => {
|
|
if (skipUpdate) {
|
|
skipUpdate = false;
|
|
return;
|
|
}
|
|
UpdateViewStore(JSON.stringify(newViewStore));
|
|
});
|
|
|
|
const views = { reload, set, subscribe, forCollection };
|
|
export default views;
|