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:
35
lib/frontend/stores/eventStore.js
Normal file
35
lib/frontend/stores/eventStore.js
Normal 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()
|
Reference in New Issue
Block a user