rasengan
Version:
The modern React Framework
45 lines (44 loc) • 1 kB
JavaScript
class ErrorStore {
errors = [];
listeners = new Set();
nextId = 1;
minimized = false;
addError(error, source = 'global', componentStack) {
this.errors = [
...this.errors,
{
id: this.nextId++,
error,
source,
timestamp: Date.now(),
componentStack,
},
];
this.notify();
}
clearAll() {
this.errors = [];
this.minimized = false;
this.notify();
}
toggleMinimize() {
this.minimized = !this.minimized;
this.notify();
}
getErrors() {
return this.errors;
}
isMinimized() {
return this.minimized;
}
subscribe(listener) {
this.listeners.add(listener);
return () => {
this.listeners.delete(listener);
};
}
notify() {
this.listeners.forEach((fn) => fn());
}
}
export const errorStore = new ErrorStore();