Skip to content

Commit

Permalink
some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
technoplato committed Mar 27, 2024
1 parent a20ff60 commit 68dead1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Machine best practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ Machine best practices
├── <domain>.machine.ts
├── <domain>.types.ts
├── <domain>.actions.ts
├── <domain>.actors.ts
├── <domain>.actors.ts

3) Should we have every actor declared in a system???
- PROS
- system.get works
- everything is explicit
- you can simulate everything in that actor system headlessly
- CONS
- Complexity...

4) Should we use emit?
I don't think so, because it causes implicit dependencies at the cost of convenience
46 changes: 44 additions & 2 deletions libs/permissions/permissionLogic/src/lib/permission-logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
sendTo,
setup,
waitFor,
createMachine,
AnyEventObject,
} from 'xstate';

import { stubApplicationLifecycleReportingActorLogic } from './lifecycle/lifecycle.stubs';
Expand Down Expand Up @@ -561,8 +563,11 @@ const permissionMonitoringMachine = setup({
permissionSubscribers: EmptyPermissionSubscriberMap,
},
on: {
// subscribeToPermissionStatuses: {},
subscribeToPermissionStatuses: {
actions: [log('received permission subscription'), log('or did we')],
},
},
// entry: raise({ type: 'subscribeToPermissionStatuses', permissions: [] }),
states: {
applicationLifecycle: {
on: {
Expand Down Expand Up @@ -631,7 +636,44 @@ describe('Permission Monitoring Machine', () => {
);
});
describe('Single Subscriber', () => {
it('should allow subscriptions from a subscriber to any permissions', () => {});
const dummyFeatureMachine = setup({
actions: {
sendSubscriptionRequestForStatusUpdates:
//TODO this is not sending figure out whhy
sendTo(
({ system }) => {
const actorRef: AnyActorRef = system.get('bigKahuna');
console.log({ actorRef });
return actorRef;
},
{
type: 'subscribeToPermissionStatuses',
// permissions: [Permissions.bluetooth],
}
),
// satisfies /*TODO type these events to the receiving machine event type*/ AnyEventObject);
},
}).createMachine({
id: 'dummyFeatureId',
entry: [
'sendSubscriptionRequestForStatusUpdates',
log('subscribe to status updates'),
],
});
it('should allow subscriptions from a subscriber to any permissions', () => {
const actor = createActor(permissionMonitoringMachine, {
parent: undefined,
systemId: 'bigKahuna',
}).start();

const dummyFeatureActor = createActor(dummyFeatureMachine).start();

const state = actor.getSnapshot();
expect(
state.context.permissionSubscribers?.[Permissions.bluetooth]
?.length ?? 0
).toEqual(1);
});
});
});
it('handle the happy path of being invoked, checking permission initially and then handle a permission request', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type PermissionStatus =
(typeof PermissionStatuses)[keyof typeof PermissionStatuses];

export type PermissionMonitoringMachineEvents =
| { type: 'subscribeToPermissionStatuses'; permissions: Permission[] }
| {
type: 'allPermissionsChecked';
statuses: PermissionStatusMapType;
Expand Down
5 changes: 4 additions & 1 deletion xstate questions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Questions about xstate:

1) Can I type the onDone events from a fromPromise event when handling them, for example, in the onDone handler?
2)
- https://discord.com/channels/795785288994652170/1021738689434501181/threads/1219788098209058897


2)

0 comments on commit 68dead1

Please sign in to comment.