MCPcopy
hub / github.com/Yqnn/svg-path-editor / save

Function save

src/app/config.service.ts:4–28  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { getConfigKey } from './constants/storage.const';
3
4function save() {
5 // eslint-disable-next-line @typescript-eslint/ban-types
6 return function(target: Object, propertyKey: string) {
7 const localStorageKey = getConfigKey(target.constructor.name, propertyKey);
8 const storedValue = localStorage.getItem(localStorageKey);
9 let value = JSON.parse(storedValue ?? 'null');
10 const wasStored = storedValue !== null;
11 let isInitialized = false;
12
13 const setter = (newVal: unknown) => {
14 if(!wasStored || isInitialized) {
15 value = newVal;
16 if(isInitialized) {
17 localStorage.setItem(localStorageKey, JSON.stringify(value));
18 }
19 }
20 isInitialized = true;
21 };
22
23 Object.defineProperty(target, propertyKey, {
24 get: () => value,
25 set: setter
26 });
27 }
28}
29
30
31

Callers 2

ConfigServiceClass · 0.85
ExportConfigServiceClass · 0.85

Calls 2

getConfigKeyFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected