File "stores.ts"

Full Path: /var/www/html/gitep_front/src/shared/model/model/stores.ts
File size: 496 bytes
MIME-type: text/x-java
Charset: utf-8

import { createStore } from "effector";
import { setModel, clearModel } from "./events";


const savedModel = localStorage.getItem("modelStore");
const initialState = savedModel ? JSON.parse(savedModel) : { model: null };

export const $modelStore = createStore<{ model: number | string | null }>(initialState)
  .on(setModel, (_, model) => ({ model }))
  .on(clearModel, () => ({ model: null }));


$modelStore.watch((state) => {
  localStorage.setItem("modelStore", JSON.stringify(state));
});