-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More moving and organizing, tests passing
- Loading branch information
1 parent
49445e0
commit c3b8061
Showing
7 changed files
with
95 additions
and
87 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
libs/permissions/permissionLogic/src/lib/applicationLifecycle/applicationLifecycle.types.ts
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
libs/permissions/permissionLogic/src/lib/lifecycle/lifecycle.stubs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { fromCallback } from 'xstate'; | ||
import { stubSubscribeToApplicationStateChanges } from './lifecycle.types'; | ||
|
||
export const stubApplicationLifecycleReportingActorLogic = | ||
// TODO figure out how to type what events this sends back | ||
fromCallback(({ sendBack }) => { | ||
/** | ||
* The real implementation of this actor should setup a subscription | ||
* to the application lifecycle events for when the application | ||
* is backgrounded or foregrounded and then report those messages via | ||
* sendBack | ||
* | ||
* Implementations should also return a function that will unsubscribe | ||
* any listeners | ||
*/ | ||
const unsubscribeApplicationStateListeners = | ||
stubSubscribeToApplicationStateChanges((event) => { | ||
switch (event) { | ||
case 'applicationForegrounded': | ||
sendBack({ type: 'applicationForegrounded' }); | ||
break; | ||
case 'applicationBackgrounded': | ||
sendBack({ type: 'applicationBackgrounded' }); | ||
break; | ||
} | ||
}); | ||
|
||
return unsubscribeApplicationStateListeners; | ||
}); |
32 changes: 32 additions & 0 deletions
32
libs/permissions/permissionLogic/src/lib/lifecycle/lifecycle.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { fromCallback } from 'xstate'; | ||
|
||
export const ApplicationLifecycleEvents = { | ||
applicationForegrounded: 'applicationForegrounded', | ||
applicationBackgrounded: 'applicationBackgrounded', | ||
} as const; | ||
|
||
export type ApplicationLifecycleEvent = | ||
(typeof ApplicationLifecycleEvents)[keyof typeof ApplicationLifecycleEvents]; | ||
|
||
export const ApplicationLifecycleStates = { | ||
applicationInForeground: 'application is in foreground', | ||
applicationInBackground: 'application is in background', | ||
} as const; | ||
|
||
export type ApplicationLifecycleState = | ||
| 'applicationForegrounded' | ||
| 'applicationBackgrounded'; | ||
|
||
export type ApplicationStateChangeHandler = ( | ||
event: ApplicationLifecycleState | ||
) => void; | ||
export const stubSubscribeToApplicationStateChanges = ( | ||
handleApplicationStateChange: ApplicationStateChangeHandler | ||
) => { | ||
console.log('subscribed to fake handler'); | ||
handleApplicationStateChange('applicationForegrounded'); | ||
|
||
return () => { | ||
console.log('unsubscribed from fake handler'); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.