MCPcopy Create free account
hub / github.com/dailydotdev/apps / handleEvents

Function handleEvents

packages/shared/src/lib/lifecycle.ts:167–214  ·  view source on GitHub ↗
(evt: Event)

Source from the content-addressed store, hash-verified

165 };
166
167 const handleEvents = (evt: Event): void => {
168 if (IS_SAFARI) {
169 clearTimeout(safariBeforeUnloadTimeout);
170 }
171
172 // eslint-disable-next-line default-case
173 switch (evt.type) {
174 case 'pageshow':
175 case 'resume':
176 dispatchChangesIfNeeded(evt, getCurrentLifecycleState());
177 break;
178 case 'focus':
179 if (wasActive) {
180 dispatchChangesIfNeeded(evt, ACTIVE);
181 }
182 break;
183 case 'scroll':
184 case 'mousedown':
185 case 'touchstart':
186 dispatchChangesIfNeeded(evt, ACTIVE);
187 break;
188 case 'blur':
189 // The `blur` event can fire while the page is being unloaded, so we
190 // only need to update the state if the current state is "active".
191 if (state === ACTIVE) {
192 dispatchChangesIfNeeded(evt, getInternalLifecycleState());
193 }
194 break;
195 case 'pagehide':
196 case 'unload':
197 dispatchChangesIfNeeded(
198 evt,
199 (evt as PageTransitionEvent).persisted ? FROZEN : TERMINATED,
200 );
201 break;
202 case 'visibilitychange':
203 // The document's `visibilityState` will change to hidden as the page
204 // is being unloaded, but in such cases the lifecycle state shouldn't
205 // change.
206 if (state !== FROZEN && state !== TERMINATED) {
207 dispatchChangesIfNeeded(evt, getInternalLifecycleState());
208 }
209 break;
210 case 'freeze':
211 dispatchChangesIfNeeded(evt, FROZEN);
212 break;
213 }
214 };
215
216 // Add capturing events on window so they run immediately.
217 EVENTS.forEach((evt) => window.addEventListener(evt, handleEvents, true));

Callers

nothing calls this directly

Calls 3

dispatchChangesIfNeededFunction · 0.85
getCurrentLifecycleStateFunction · 0.85

Tested by

no test coverage detected