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

Function dispatchChangesIfNeeded

packages/shared/src/lib/lifecycle.ts:132–165  ·  view source on GitHub ↗
(
    originalEvent: Event,
    newState: string,
  )

Source from the content-addressed store, hash-verified

130 }
131
132 const dispatchChangesIfNeeded = (
133 originalEvent: Event,
134 newState: string,
135 ): void => {
136 if (newState === PASSIVE && wasActive) {
137 // eslint-disable-next-line no-param-reassign
138 newState = ACTIVE;
139 }
140 if (newState !== state) {
141 const oldState = state;
142 const path = getLegalStateTransitionPath(oldState, newState);
143
144 for (let i = 0; i < path.length - 1; i += 1) {
145 const oldPathState = path[i];
146 const newPathState = path[i + 1];
147
148 state = newState;
149 if (state === ACTIVE) {
150 wasActive = true;
151 }
152
153 window.dispatchEvent(
154 new CustomEvent('statechange', {
155 bubbles: true,
156 detail: {
157 oldState: oldPathState,
158 newState: newPathState,
159 originalEvent,
160 },
161 }),
162 );
163 }
164 }
165 };
166
167 const handleEvents = (evt: Event): void => {
168 if (IS_SAFARI) {

Callers 2

handleEventsFunction · 0.85
listenToLifecycleEventsFunction · 0.85

Calls 1

Tested by

no test coverage detected