1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-06-05 22:09:25 +02:00

feature: create event store in preparation of table component

replacement
This commit is contained in:
Ondřej Synáček
2020-12-15 21:48:38 +01:00
parent e28b378e07
commit 985b580d7d
4 changed files with 52 additions and 3 deletions

View File

@ -0,0 +1,35 @@
import { writable } from 'svelte/store'
import { STORAGE_KEYS } from '../services/storageListener'
const createEventStore = () => {
const state = JSON.parse(localStorage.getItem(STORAGE_KEYS.EVENTS) || '[]')
const { subscribe, set, update } = writable(state)
const setCalculation = ({ id, link, createdAt, startTime, title }) => {
update((prevState) => ([
...prevState,
{
id,
link,
createdAt: createdAt.toString(),
startTime: startTime.toString(),
title,
},
]))
}
const getState = () => state
return {
...state,
subscribe,
set,
update,
setCalculation,
getState,
}
}
export default createEventStore()