Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@manojadams/session-store

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@manojadams/session-store - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

src/constants.ts

2

package.json
{
"name": "@manojadams/session-store",
"version": "1.0.1",
"version": "1.0.2",
"description": "Simple state management with session storage",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -0,1 +1,2 @@

import { IStore } from "./constants";

@@ -6,7 +7,15 @@ /**

*/
abstract class SessionStore<T> {
abstract class SessionStore<T extends IStore> {
protected __sessionData: T;
protected _name: string;
protected _createdAt: Date;
protected _updatedAt: Date;
isReady: boolean;
constructor() {
constructor(_name?: string) {
this._name = _name || this.constructor.name;
this.__sessionData = <T>{};
this._createdAt = new Date();
this._updatedAt = new Date();
this.isReady = false;
}

@@ -16,9 +25,5 @@

const storeName = this.constructor.name;
try {
const sessionData = sessionStorage.getItem(storeName);
if (sessionData) {
this.__sessionData = JSON.parse(sessionData);
}
} catch {
console.error("store_init_error\t:", storeName);
const sessionData = sessionStorage.getItem(storeName);
if (sessionData) {
this.__sessionData = JSON.parse(sessionData);
}

@@ -33,10 +38,15 @@ }

this.__sessionData[dataKey] = value;
this._updatedAt = new Date();
}
destroy() {
const storeName = this.constructor.name;
sessionStorage.setItem(storeName, JSON.stringify(this.__sessionData));
const createdAt = this.getData("_createdAt") || this._createdAt.toISOString();
const updatedAt = this._updatedAt.toISOString();
this.setData("_createdAt", createdAt);
this.setData("_updatedAt", updatedAt);
sessionStorage.setItem(this._name, JSON.stringify(this.__sessionData));
}
}
export default SessionStore;
export default SessionStore;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc