({ store: externalStore, children }: Props)
| 107 | }; |
| 108 | |
| 109 | export function StatsProvider({ store: externalStore, children }: Props): React.ReactNode { |
| 110 | const internalStore = useMemo(() => createStatsStore(), []); |
| 111 | const store = externalStore ?? internalStore; |
| 112 | |
| 113 | useEffect(() => { |
| 114 | const flush = () => { |
| 115 | const metrics = store.getAll(); |
| 116 | if (Object.keys(metrics).length > 0) { |
| 117 | saveCurrentProjectConfig(current => ({ |
| 118 | ...current, |
| 119 | lastSessionMetrics: metrics, |
| 120 | })); |
| 121 | } |
| 122 | }; |
| 123 | process.on('exit', flush); |
| 124 | return () => { |
| 125 | process.off('exit', flush); |
| 126 | }; |
| 127 | }, [store]); |
| 128 | |
| 129 | return <StatsContext.Provider value={store}>{children}</StatsContext.Provider>; |
| 130 | } |
| 131 | |
| 132 | export function useStats(): StatsStore { |
| 133 | const store = useContext(StatsContext); |
nothing calls this directly
no test coverage detected