Open bmblb opened 1 year ago
Workaround is to define own storage:
// gantt.config.ts
import { StateProvider, StateStorage } from '@bryntum/gantt';
const
empty = () => Object.create(null),
getKeys = (prefix, pos = 0) => {
const
keys = [],
count = localStorage.length;
for (let key, i = 0; i < count; ++i) {
key = localStorage.key(i);
key.startsWith(prefix) && keys.push(key.slice(pos));
}
return keys;
};
//@ts-ignore
export class LocalStorage extends StateStorage {
prefix = '';
constructor(stateProvider) {
super();
this.prefix = stateProvider.prefix || '';
}
get isLocal() {
return true;
}
//@ts-ignore
get data() {
const
data = empty(),
keys = this.keys;
for (const key of keys) {
data[key] = this.getItem(key);
}
return data;
}
//@ts-ignore
get keys() {
return getKeys(this.prefix, this.prefix.length);
}
clear() {
// It's important that we only clear our own StateProvider's keys, not all of localStorage. We get the
// full keys not the suffixes since we're just going to call removeItem() with them...
const keys = getKeys(this.prefix);
for (const key of keys) {
localStorage.removeItem(key);
}
}
getItem(key) {
const value = localStorage.getItem(this.prefix + key);
// We handle the JSON translation at this layer because the Memory storage does not do any such pickling
// of data but localStorage only handles strings
return (value === null) ? value : JSON.parse(value);
}
removeItem(key) {
return localStorage.removeItem(this.prefix + key);
}
setItem(key, value) {
return localStorage.setItem(this.prefix + key, JSON.stringify(value));
}
}
const ganttConfig = {
//@ts-ignore
stateProvider : StateProvider.setup(LocalStorage),
...
Reported by client.
To reproduce on advanced angular demo:
const ganttConfig = { stateProvider : StateProvider.setup('local'), stateId : 'foo',
// app/gantt/gantt.component.html [stateId] = "ganttConfig.stateId" [stateProvider] = "ganttConfig.stateProvider"
npm run build serve -s dest/advanced
Uncaught TypeError: Super constructor null of local is not a constructor
Local = class extends StateStorage { constructor(stateProvider) { super(); this.prefix = stateProvider.prefix || ''; }