Skip to content

Commit 59ad3da

Browse files
committed
Clean up permission reporting machine
1 parent a96fab6 commit 59ad3da

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

libs/permissions/permissionLogic/src/lib/permission/reporting/permissionReporting.machine.ts

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ export const permissionReportingMachine = setup({
3636
self,
3737
})
3838
),
39+
sendTriggerPermissionRequest: sendTo(
40+
({ system }) => {
41+
return system.get(ActorSystemIds.permissionCheckerAndRequester);
42+
},
43+
({ event }) => ({
44+
// TODO: determine how to make this typesafe
45+
// I'm thinking an api like sendToPermissionChecker(event: PermissionCheckerEvent)
46+
type: 'triggerPermissionRequest',
47+
permission: event.permission,
48+
})
49+
),
3950
checkedSendParent: enqueueActions(
4051
({ context, enqueue }, event: AnyEventObject) => {
4152
if (!context.parent) {
@@ -51,8 +62,12 @@ export const permissionReportingMachine = setup({
5162
},
5263
}).createMachine({
5364
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAYgCcwBHAVzgBcAFMM1XWWXAe3wG0AGALqJQAB04c6XfMJAAPRAFoATADYAnADoA7AFYALDoDMevgb4AOIwBoQAT0QBGPRrVqlai050O3Sh1oBfAJs0LDxCUhFmVnYpAGU6dDpqWABhbHR8GAh+ISQQMQkpGXkEQ3NNFRU+NX8+U3M+LS09G3sEZXMNbz4dJX0DPS1LJyCQjBwCYg0Ad3RcSSySWVhEujANdAAzdbJkPlJQyYjZ+cWoXJlCheL80qG2xG8dDUa9FXMVB0MfwzUVILBED4TgQOAyI7hYhXcQ3bglRQOR5lPgqDQOHS6HT6PzqIxjECQqZEU43LIworwu6OHRotRaJoOBx8QxaJzmJTIr6GDRNczfCzlcx6IaAgJAA */
54-
description:
55-
"This actor's job is to report permission statuses to the actors that have invoked it. We abstract away this functionality so that it is reusable by any actor that needs it and so they don't need to know how permissions are checked. This keeps control centralized and easy to modify the behavior of.",
65+
description: `
66+
This actor's job is to report permission statuses to the actors that have invoked it.
67+
We abstract away this functionality so that it is reusable by any actor that needs it
68+
and so they don't need to know how permissions are checked. This keeps control
69+
centralized and easy to modify the behavior of.
70+
`,
5671
context: ({ input }) => ({
5772
permissions: input.permissions,
5873
parent: input.parent,
@@ -72,35 +87,18 @@ export const permissionReportingMachine = setup({
7287
},
7388
on: {
7489
requestPermission: {
90+
actions: ['sendTriggerPermissionRequest'],
7591
description: `
7692
This event is sent to the permission reporting machine from its parent feature machine.
7793
7894
This will trigger the "real" check whose results will then be sent to the feature
7995
machine.
80-
`,
81-
actions: [
82-
sendTo(
83-
({ system }) => {
84-
return system.get(ActorSystemIds.permissionCheckerAndRequester);
85-
},
86-
({ event }) => ({
87-
// TODO: determine how to make this typesafe
88-
// I'm thinking an api like sendToPermissionChecker(event: PermissionCheckerEvent)
89-
type: 'triggerPermissionRequest',
90-
permission: event.permission,
91-
})
92-
),
93-
],
96+
`,
9497
},
9598
permissionStatusChanged: {
96-
description:
97-
'Whenever the Permission Monitoring machine reports that a permission status has changed, we receive this event and can process and share with our siblings.',
99+
description: `Whenever the Permission Monitoring machine reports that a permission
100+
status has changed, we receive this event and can process and share with our siblings.`,
98101
actions: [
99-
log(
100-
({ event }) =>
101-
event.permission + ' status <<<changed' + ' to ' + event.status
102-
),
103-
104102
{
105103
/**
106104
* I tried putting this action in the actions in setup as reportPermissionRequestResult
@@ -114,11 +112,7 @@ machine.
114112
type: 'checkedSendParent',
115113
params({ event }) {
116114
const { permission, status } = event;
117-
console.log(JSON.stringify(event, null, 2));
118-
119115
const permissionEventType = `permissions.${permission}.${status}`;
120-
console.log(JSON.stringify(permissionEventType, null, 2));
121-
122116
return { type: permissionEventType };
123117
},
124118
},

0 commit comments

Comments
 (0)