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

Function getLegalStateTransitionPath

packages/shared/src/lib/lifecycle.ts:54–79  ·  view source on GitHub ↗
(
  oldState: string,
  newState: string,
)

Source from the content-addressed store, hash-verified

52 * @return {!Array<string>}
53 */
54const getLegalStateTransitionPath = (
55 oldState: string,
56 newState: string,
57): string[] => {
58 // We're intentionally not using for...of here so when we transpile to ES5
59 // we don't need to include the Symbol polyfills.
60 for (
61 let order: Record<string, number>, i = 0;
62 i < LEGAL_STATE_TRANSITIONS.length;
63 i += 1
64 ) {
65 order = LEGAL_STATE_TRANSITIONS[i];
66 const oldIndex = order[oldState];
67 const newIndex = order[newState];
68
69 if (oldIndex >= 0 && newIndex >= 0 && newIndex > oldIndex) {
70 // Differences greater than one should be reported
71 // because it means a state was skipped.
72 return Object.keys(order).slice(oldIndex, newIndex + 1);
73 }
74 }
75 return [];
76 // TODO(philipwalton): it shouldn't be possible to get here, but
77 // consider some kind of warning or call to action if it happens.
78 // console.warn(`Invalid state change detected: ${oldState} > ${newState}`);
79};
80
81let wasActive = false;
82

Callers 1

dispatchChangesIfNeededFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected