🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@mkgalaxy/utilities

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mkgalaxy/utilities - npm Package Compare versions

Comparing version
0.2.6
to
0.2.7
+5
dist/GeneralAppContext/generalStorage.d.ts
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);
}
};
+20
-1

@@ -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": {