import { ExtensionItem } from '../src/API' // Naive signals implementation interface Signal { get(): T set(value: T): void } let currentEffect: (() => void) | null = null const signal = (initialValue: T): Signal => { let value = initialValue const subscribers = new Set<() => void>() return { get: () => { if (currentEffect) { subscribers.add(currentEffect) } return value }, set: (newValue: T) => { value = newValue subscribers.forEach(fn => fn()) } } } const effect = (fn: () => void): (() => void) => { const execute = () => { currentEffect = execute fn() currentEffect = null } execute() return () => { currentEffect = null } } export const createSignalItemsDataStructure = () => { let signalToTrack: Signal[]> | null = null return { createDataStructure: () => { const itemsSignal = signal[]>([]) signalToTrack = itemsSignal return { get: () => itemsSignal.get(), add: (item: ExtensionItem) => { itemsSignal.set([...itemsSignal.get(), item]) }, discardBy: (predicate: (item: ExtensionItem) => boolean) => { itemsSignal.set(itemsSignal.get().filter(predicate)) } } }, getSignalToTrack: () => { if (!signalToTrack) { throw new Error('Signal to track is not set') } return signalToTrack }, effect } }