Skip to content

Commit

Permalink
Moving completed
Browse files Browse the repository at this point in the history
  • Loading branch information
technoplato committed Apr 9, 2024
1 parent 5409d50 commit 7a23891
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 95 deletions.
4 changes: 2 additions & 2 deletions libs/permissions/permissionLogic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const foo = 'bar';
export * from './lib/permissionMonitor.machine';
export * from './lib/permissionCheckAndRequestMachine';
export * from './lib/permission/monitoring/permissionMonitor.machine';
export * from './lib/permission/checkAndRequest/permissionCheckAndRequestMachine';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PermissionStatus,
PermissionStatuses,
} from '../../permission.types';
import { permissionReportingMachine } from '../../permission/permissionReporting/permissionReporting.machine';
import { permissionReportingMachine } from '../../permission/reporting/permissionReporting.machine';

export const countingMachineThatNeedsPermissionAt3 = setup({
actors: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const featuresMachine = setup({
types: {} as {
children: {
[ActorSystemIds.counting]: 'countingMachine';
// [ActorSystemIds.someFeature]: 'someFeatureMachine';
[ActorSystemIds.someFeature]: 'someFeatureMachine';
};
},
actors: {
countingMachine: countingMachineThatNeedsPermissionAt3,
// someFeatureMachine: someFeatureMachine,
someFeatureMachine: someFeatureMachine,
},
}).createMachine({
entry: log('Features started'),
Expand All @@ -23,10 +23,10 @@ export const featuresMachine = setup({
systemId: ActorSystemIds.counting,
src: 'countingMachine',
},
// {
// id: ActorSystemIds.someFeature,
// systemId: ActorSystemIds.someFeature,
// src: 'someFeatureMachine',
// },
{
id: ActorSystemIds.someFeature,
systemId: ActorSystemIds.someFeature,
src: 'someFeatureMachine',
},
],
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { raise, sendTo, setup } from 'xstate';
import { permissionReportingMachine } from '../../permission/permissionReporting/permissionReporting.machine';
import { Permissions } from '../../permission.types';
import { permissionReportingMachine } from '../../permission/reporting/permissionReporting.machine';

export const someFeatureMachine = setup({
actors: {
Expand Down Expand Up @@ -59,14 +59,14 @@ export const someFeatureMachine = setup({
],
},
},
// invoke: {
// id: 'permissionHandler',
// src: 'permissionReportingMachine',
// input: ({ self }) => ({
// permissions: [Permissions.bluetooth],
// parent: self,
// }),
// },
invoke: {
id: 'permissionHandler',
src: 'permissionReportingMachine',
input: ({ self }) => ({
permissions: [Permissions.bluetooth],
parent: self,
}),
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import {
} from 'xstate';
import {
Permission,
PermissionMonitoringMachineEvents,
Permissions,
PermissionStatuses,
} from './permission.types';
import { permissionCheckerAndRequesterMachine } from './permissionCheckAndRequestMachine';
import { permissionCheckerAndRequesterMachine } from './permission/checkAndRequest/permissionCheckAndRequestMachine';
import {
EmptyPermissionSubscriberMap,
permissionMonitoringMachine,
} from './permissionMonitor.machine';
} from './permission/monitoring/permissionMonitor.machine';
import { someFeatureMachine } from './features/someFeature/someFeature.machine';
import { countingMachineThatNeedsPermissionAt3 } from './features/counting/counting.machine';
import { applicationMachine } from './application/application.machine';
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions libs/permissions/permissionLogic/src/lib/permission.actions.ts

This file was deleted.

40 changes: 0 additions & 40 deletions libs/permissions/permissionLogic/src/lib/permission.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,9 @@ export const PermissionStatuses = {
export type PermissionStatus =
(typeof PermissionStatuses)[keyof typeof PermissionStatuses];

export type PermissionMonitoringMachineEvents =
| {
type: 'subscribeToPermissionStatuses';
permissions: Permission[];
self: AnyActorRef;
}
| {
type: 'allPermissionsChecked';
statuses: PermissionStatusMapType;
}
| { type: 'triggerPermissionRequest'; permission: Permission }
| {
type: 'permissionRequestCompleted';
status: PermissionStatus;
permission: Permission;
}
| { type: 'triggerPermissionCheck' }
| { type: 'applicationForegrounded' }
| { type: 'applicationBackgrounded' };

export interface PermissionMachineActions {
checkAllPermissions: () => Promise<PermissionStatusMapType>;
requestBluetoothPermission: () => Promise<PermissionStatus>;
requestMicrophonePermission: () => Promise<PermissionStatus>;
}

export type PermissionStatusMapType = Record<Permission, PermissionStatus>;

export const PermissionCheckingStates = {
idle: 'idle',
checking: 'checking',
} as const;

export type PermissionMonitoringMachineContext = {
permissionStatuses: PermissionStatusMapType;
};

export type PermissionMachineEvents =
| { type: 'triggerPermissionCheck' }
| {
type: 'triggerPermissionRequest';
permission: Permission;
};

export type PermissionSubscribers = Array<AnyActorRef>;
export type PermissionSubscriberMap = Record<Permission, PermissionSubscribers>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PermissionStatuses, Permissions } from '../../permission.types';
import { PermissionCheckAndRequestMachineActions } from './permissionCheckAndRequest.types';

export const unimplementedPermissionCheckAndRequestActions: PermissionCheckAndRequestMachineActions =
{
checkAllPermissions: () => {
return new Promise((resolve) =>
resolve({
[Permissions.bluetooth]: PermissionStatuses.denied,
[Permissions.microphone]: PermissionStatuses.denied,
})
);
},
requestBluetoothPermission: () => {
return new Promise((resolve) => resolve(PermissionStatuses.granted));
},
requestMicrophonePermission: () => {
return new Promise((resolve) => resolve(PermissionStatuses.granted));
},
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
Permission,
PermissionStatus,
PermissionStatusMapType,
} from '../../permission.types';

export interface PermissionCheckAndRequestMachineActions {
checkAllPermissions: () => Promise<PermissionStatusMapType>;
requestBluetoothPermission: () => Promise<PermissionStatus>;
requestMicrophonePermission: () => Promise<PermissionStatus>;
}

export type PermissionMachineEvents =
| { type: 'triggerPermissionCheck' }
| {
type: 'triggerPermissionRequest';
permission: Permission;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {
sendTo,
setup,
} from 'xstate';
import { ActorSystemIds } from './application/actorIds';
import { stubApplicationLifecycleReportingActorLogic } from './lifecycle/lifecycle.stubs';
import { InitialPermissionStatusMap } from './permission.fixtures';
import { ActorSystemIds } from '../../application/actorIds';
import { stubApplicationLifecycleReportingActorLogic } from '../../lifecycle/lifecycle.stubs';
import { InitialPermissionStatusMap } from '../../permission.fixtures';
import {
Permission,
PermissionMonitoringMachineEvents,
PermissionStatusMapType,
Permissions,
PermissionStatusMapType,
} from '../../permission.types';
import { permissionCheckerAndRequesterMachine } from '../checkAndRequest/permissionCheckAndRequestMachine';
import {
PermissionMonitoringMachineEvents,
PermissionSubscriberMap,
} from './permission.types';
import { permissionCheckerAndRequesterMachine } from './permissionCheckAndRequestMachine';
import { countingMachineThatNeedsPermissionAt3 } from './features/counting/counting.machine';
import { someFeatureMachine } from './features/someFeature/someFeature.machine';
} from './permissionMonitor.types';

export const EmptyPermissionSubscriberMap: PermissionSubscriberMap =
Object.values(Permissions).reduce(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AnyActorRef } from 'xstate';
import {
Permission,
PermissionStatus,
PermissionStatusMapType,
} from '../../permission.types';

export type PermissionMonitoringMachineEvents =
| {
type: 'subscribeToPermissionStatuses';
permissions: Permission[];
self: AnyActorRef;
}
| {
type: 'allPermissionsChecked';
statuses: PermissionStatusMapType;
}
| { type: 'triggerPermissionRequest'; permission: Permission }
| {
type: 'permissionRequestCompleted';
status: PermissionStatus;
permission: Permission;
}
| { type: 'triggerPermissionCheck' }
| { type: 'applicationForegrounded' }
| { type: 'applicationBackgrounded' };

export type PermissionMonitoringMachineContext = {
permissionStatuses: PermissionStatusMapType;
};

export type PermissionSubscribers = Array<AnyActorRef>;
export type PermissionSubscriberMap = Record<Permission, PermissionSubscribers>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMachine, setup } from 'xstate';
import { ActorSystemIds } from '../application/actorIds';
import { permissionMonitoringMachine } from '../permissionMonitor.machine';
import { permissionMonitoringMachine } from '../permission/monitoring/permissionMonitor.machine';

export const systemManagementMachine = setup({
types: {} as {
Expand Down

0 comments on commit 7a23891

Please sign in to comment.