Skip to content

Commit

Permalink
make actions more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
technoplato committed Mar 26, 2024
1 parent be20ca0 commit cfc9c9e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions libs/permissions/permissionLogic/src/lib/permission-logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,24 @@ describe('permission requester and checker machine', () => {
};
},
}),
raisePermissionCheck: raise({ type: 'triggerPermissionCheck' }),
sendPermissionCheck: sendTo('someFooMachine', {
type: 'triggerPermissionCheck',
}),
sendPermissionRequest: sendTo(
'someFooMachine',
({ context, event }) => {
assertEvent(event, 'triggerPermissionRequest');

return {
type: 'triggerPermissionRequest',
permission: event.permission,
};
}
),
},
}).createMachine({
/** @xstate-layout N4IgpgJg5mDOIC5QCMCWUDSBDAFgVwDssA6LABzIBtUBjLAF1QHsCAZVAMzBoE8bKwAYnJVaDZgQBiTAE5goMpoQiQA2gAYAuolBkmsVIxY6QAD0QBaAKxWA7MQAcAJgCcrpwDYnVgIx2ALAA0IDyITupOxOrqAMzhDg4xDuq2Pn4AvunBaJi4hCQi1HRGbJzcfALCFEXiLABCWDQA1gpKBCoQGtpIIHoGJSbmCNZWLsSjHg62Vh4xLlNuwaEIMT4OxD5Oqf4+-up2sR6Z2ejY+ETEZGAyALaosAYssMKUlAAK13cPErAAwjjcJpqLQmPqGCSDRAxfyRdQwhIeHZWGJw-ZLSxrdQbWa2Wxw-wuabRJzHEA5M75S6fe6PAjPegydAwGQfW40iT-QFdUH6cHGHpDCz+DzEHbqPxzTzOGK2FwedHDHwuGKi1LqBw7DUeKz7Byk8l5C5XNnfJ6CBlM66sr60gBKYAAjng4PRuT0wQMBWFYepJoTJg55jDvAroZEZbinKs4lGPEcsmTToaSMabT9BKn2Sx7U6XcDurpeZ7QEMZVi-C4CbqnA4fOoXKHJo4YtDAy2ptCrJkEwQmCp4D0DecsDz+hCvcNtVZxnKpjM5gsnAqLDWsbK5oTwr7ov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PWLCdS0sVwnBnV81WJBxq3FHwvzhGE3G1SVUlfZdDyOZiqSzM16Vw0T8IQfYYX8Tx9ncbFI0bOViA8GVQmrcJIV2SsezSIA */
id: 'bigKahuna',
type: 'parallel',

Expand All @@ -135,7 +150,7 @@ describe('permission requester and checker machine', () => {
},

applicationBackgrounded: {
target: '.applicationInInBackground',
target: '.applicationInBackground',
},
},
initial: 'applicationIsInForeground',
Expand All @@ -145,9 +160,9 @@ describe('permission requester and checker machine', () => {

states: {
applicationIsInForeground: {
entry: raise({ type: 'triggerPermissionCheck' }),
entry: 'raisePermissionCheck',
},
applicationInInBackground: {},
applicationInBackground: {},
},
},

Expand All @@ -157,24 +172,12 @@ describe('permission requester and checker machine', () => {
actions: 'assignPermissionCheckResultsToContext',
},
triggerPermissionCheck: {
actions: [
log('permission trigger check'),
sendTo('someFooMachine', {
type: 'triggerPermissionCheck',
}),
],
actions: [log('permission trigger check'), 'sendPermissionCheck'],
},
triggerPermissionRequest: {
actions: [
log('triggering permission request'),
sendTo('someFooMachine', ({ context, event }) => {
assertEvent(event, 'triggerPermissionRequest');

return {
type: 'triggerPermissionRequest',
permission: event.permission,
};
}),
'sendPermissionRequest',
],
},

Expand Down

0 comments on commit cfc9c9e

Please sign in to comment.