@mkgalaxy/utilities
Advanced tools
| import { AppState } from "./GeneralAppReducer"; | ||
| export declare const loadState: () => { | ||
| [key: string]: any; | ||
| }; | ||
| export declare const saveState: (state: AppState) => void; |
| var STORAGE_KEY = "general_app_state"; | ||
| export var loadState = function () { | ||
| if (typeof window === "undefined") | ||
| return undefined; | ||
| try { | ||
| var serializedState = localStorage.getItem(STORAGE_KEY); | ||
| if (!serializedState) | ||
| return undefined; | ||
| return JSON.parse(serializedState); | ||
| } | ||
| catch (err) { | ||
| console.error("Error loading state:", err); | ||
| return undefined; | ||
| } | ||
| }; | ||
| export var saveState = function (state) { | ||
| if (typeof window === "undefined") | ||
| return; | ||
| try { | ||
| var serializedState = JSON.stringify(state.dynamicData); | ||
| localStorage.setItem(STORAGE_KEY, serializedState); | ||
| } | ||
| catch (err) { | ||
| console.error("Error saving state:", err); | ||
| } | ||
| }; |
@@ -13,4 +13,5 @@ var __assign = (this && this.__assign) || function () { | ||
| import { jsx as _jsx } from "react/jsx-runtime"; | ||
| import { createContext, useReducer, useContext, } from "react"; | ||
| import { createContext, useReducer, useContext, useEffect, } from "react"; | ||
| import { reducer, initialState, } from "./GeneralAppReducer"; | ||
| import { loadState, saveState } from "./generalStorage"; | ||
| /* | ||
@@ -53,2 +54,20 @@ USAGE EXAMPLE: | ||
| var _b = useReducer(reducer, initialState), state = _b[0], dispatch = _b[1]; | ||
| console.log("✅ GeneralAppProvider state:", state); | ||
| useEffect(function () { | ||
| if (typeof window !== "undefined") { | ||
| console.log("✅ GeneralAppProvider fetching state from localstorage:", state); | ||
| var savedState = loadState(); | ||
| if (savedState) { | ||
| // Update all saved values at once | ||
| dispatch({ | ||
| type: "UPDATE_DYNAMIC_VALUES", | ||
| payload: savedState, | ||
| }); | ||
| } | ||
| } | ||
| }, []); | ||
| useEffect(function () { | ||
| console.log("✅ GeneralAppProvider saving state in localstorage:", state); | ||
| saveState(state); | ||
| }, [state]); | ||
| return (_jsx(StateContext.Provider, __assign({ value: state }, { children: _jsx(DispatchContext.Provider, __assign({ value: dispatch }, { children: children })) }))); | ||
@@ -55,0 +74,0 @@ }; |
+1
-1
| { | ||
| "name": "@mkgalaxy/utilities", | ||
| "version": "0.2.6", | ||
| "version": "0.2.7", | ||
| "main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
84291
2.08%33
6.45%1398
3.71%