opendash
Version:
open.DASH data visualization framework
52 lines • 1.34 kB
JavaScript
import { Store } from "..";
export function createState() {
var cacheKey = "opendash/state/cache";
var cache = loadCache(cacheKey);
var store = new Store(cache || {
user: {
current: undefined,
validated: false,
offline: false,
},
collaboration: {
users: [],
roles: [],
},
sources: {
current: undefined,
all: [],
},
dashboards: {
dashboards: [],
widgets: [],
currentDashboard: undefined,
linkedItem: undefined,
linkedHistory: {},
},
navigation: {
userNavigationGroups: [],
userNavigationItems: [],
},
});
store.subscribe(function () {
saveCache(cacheKey, store.state());
});
return store;
}
function loadCache(cacheKey) {
try {
return JSON.parse(window.localStorage.getItem(cacheKey));
}
catch (error) {
return null;
}
}
function saveCache(cacheKey, state) {
try {
window.localStorage.setItem(cacheKey, JSON.stringify(state));
}
catch (error) {
console.error("Error writing " + cacheKey, error);
}
}
//# sourceMappingURL=createState.js.map