error-flux
Version:
Network request interceptor and logger for web applications
41 lines • 1.27 kB
JavaScript
// Global state store for ErrorFlux
// This is a simple state management solution for vanilla JS
import { StorageTypes } from "../types";
const defaultState = {
dbName: "ErrorFluxDB",
storeName: {
networkLogs: "networkLogs",
consoleErrors: "consoleErrors",
unhandledErrors: "unhandledErrors",
},
pattern: ".*",
allowOnlyNetworkErrors: true,
storageType: StorageTypes.IndexedDB,
};
class ErrorFluxStore {
constructor(initialState) {
this.listeners = [];
this.state = Object.assign(Object.assign({}, defaultState), initialState);
}
getState() {
return Object.assign({}, this.state);
}
setState(newState) {
this.state = Object.assign(Object.assign({}, this.state), newState);
this.notifyListeners();
}
subscribe(listener) {
this.listeners.push(listener);
// Return unsubscribe function
return () => {
this.listeners = this.listeners.filter((l) => l !== listener);
};
}
notifyListeners() {
this.listeners.forEach((listener) => listener(this.getState()));
}
}
// Create and export a singleton instance
const store = new ErrorFluxStore();
export default store;
//# sourceMappingURL=store.js.map