diff --git a/libs/permissions/permissionLogic/src/lib/features/counting/counting.machine.ts b/libs/permissions/permissionLogic/src/lib/features/counting/counting.machine.ts index 97495ea..31bc97f 100644 --- a/libs/permissions/permissionLogic/src/lib/features/counting/counting.machine.ts +++ b/libs/permissions/permissionLogic/src/lib/features/counting/counting.machine.ts @@ -1,4 +1,4 @@ -import { assign, log, not, raise, sendTo, setup } from 'xstate'; +import { assign, not, sendTo, setup } from 'xstate'; import { Permission, PermissionStatus, @@ -15,8 +15,9 @@ export const countingMachineThatNeedsPermissionAt3 = setup({ actions: { incrementCount: assign({ count: ({ context }) => context.count + 1 }), assignBluetoothStatusGranted: assign({ permissionStatus: 'granted' }), - triggerBluetoothPermissionRequest: raise({ - type: 'permissionWasRequested', + + triggerBluetoothPermissionRequest: sendTo('permissionReportingCounting', { + type: 'requestPermission', permission: Permissions.bluetooth, }), }, @@ -30,21 +31,18 @@ export const countingMachineThatNeedsPermissionAt3 = setup({ types: { context: {} as { count: number; permissionStatus: PermissionStatus }, - events: - {} as // TODO pull these out into their own discrete types and do a union here + events: {} as // TODO pull these out into their own discrete types and do a union here | { type: 'count.inc' } - | { type: 'permissions.bluetooth.revoked' } - | { type: 'permissions.bluetooth.granted' } - | { type: 'permissions.bluetooth.denied' } - | { type: 'permissionWasRequested'; permission: Permission } - | { - type: 'user.didTapBluetoothRequestPermission'; - permission: Permission; - }, + | { type: 'permissions.bluetooth.revoked' } + | { type: 'permissions.bluetooth.granted' } + | { type: 'permissions.bluetooth.denied' } + | { + type: 'user.didTapBluetoothRequestPermission'; + permission: Permission; + }, }, }).createMachine({ /** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAYgAcwAnVXWWXAe31gDoAjAGwFcwAXBhr2wtKYAG4MA1pADaABgC6iUGQb1ejfMpAAPRAFoAjADYArCwAshgJwAmABwBmC6YDst03YA0IAJ6JHQzlLazkrR1tHOUjHVwBfOJ80LDxCIhYwfHROSBJMBi58XhYCTHklJBBVdU1tPQR7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atus: PermissionStatuses.unasked, @@ -72,12 +70,12 @@ export const countingMachineThatNeedsPermissionAt3 = setup({ enabled: { always: [ { - target: 'handlingPermissions', guard: 'isPermissionRequiredToContinue', + target: 'handlingPermissions', }, { - target: 'finished', guard: 'isCountingCompleted', + target: 'finished', }, ], on: { @@ -90,12 +88,7 @@ export const countingMachineThatNeedsPermissionAt3 = setup({ handlingPermissions: { on: { 'user.didTapBluetoothRequestPermission': { - actions: sendTo('permissionReportingCounting', ({ event }) => { - return { - type: 'requestPermission', - permission: Permissions.bluetooth, - }; - }), + actions: 'triggerBluetoothPermissionRequest', }, 'permissions.bluetooth.granted': { @@ -110,12 +103,7 @@ export const countingMachineThatNeedsPermissionAt3 = setup({ on: { 'permissions.bluetooth.granted': { target: 'enabled', - actions: [ - 'assignBluetoothStatusGranted', - log(({ event }) => { - console.log(JSON.stringify(event, null, 2)); - }), - ], + actions: ['assignBluetoothStatusGranted'], }, 'user.didTapBluetoothRequestPermission': { actions: 'triggerBluetoothPermissionRequest',