Skip to content

Add controller messaging system - #377

Merged
Gudahtt merged 6 commits into
developfrom
controller-messaging
Mar 11, 2021
Merged

Gudahtt merged 6 commits into
developfrom
controller-messaging

Conversation

@Gudahtt

@Gudahtt Gudahtt commented Mar 5, 2021 •

Copy link
Copy Markdown
Member

Adds a controller messaging system, which will be used to facilitate inter-controller communication. The controller messenger acts as a message broker, passing actions and events back and forth between controllers. It is fully type safe.

This idea was described in the Controller Messaging System proposal.

This controller messenger doesn't yet support attenuation, so it's not yet possible to restrict which actions and events are interacted with. That will be coming in a later PR.

@Gudahtt
Gudahtt force-pushed the controller-messaging branch from 0e63938 to e803cc0 Compare March 5, 2021 18:22
Comment thread src/ControllerMessenger.ts Outdated
@Gudahtt
Gudahtt force-pushed the controller-messaging branch 4 times, most recently from c86d06e to 159d49e Compare March 8, 2021 14:29
@Gudahtt
Gudahtt force-pushed the controller-messaging branch from 159d49e to 756e986 Compare March 8, 2021 14:38
Comment thread src/ControllerMessenger.ts Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get rid of this any 🤔 Using unknown or unknown[] seemed to upset TypeScript. What I wanted here was to express that I don't know anything about these parameters, but I don't know how to do that.

Though, maybe it's fine to leave this as-is. There are unit tests for zero parameters, one parameter, and multiple parameters (of various different types). Those should be sufficient for ensuring we're not assuming anything about these parameters in this class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i was trying to figure out types I had to do some 'any' to allow it to work, even though I had full type safety in practice. Hard to explain/understand why that was true but I think it's fine as is

@Gudahtt
Gudahtt marked this pull request as ready for review March 8, 2021 14:44
@Gudahtt
Gudahtt requested a review from a team as a code owner March 8, 2021 14:44
@Gudahtt

Gudahtt commented Mar 8, 2021 •

Copy link
Copy Markdown
Member Author

Attenuation is added in this follow-up PR: #378. It's still a work-in-progress, but that should give some idea what attenuation could look like.

@Gudahtt

Gudahtt commented Mar 8, 2021

Copy link
Copy Markdown
Member Author

I don't yet have tests for ensuring this is type-safe. There is no straightforward way of testing this, as any misuse of types would fail to compile, and JavaScript tests wouldn't test the types at all.

There are some libraries that could help here though. I've opened #379 for investigating this further.

In the meantime I've been testing that this is type-safe by manually editing the unit tests into various type violations, and ensuring I get an error when I run the tests.

Comment thread src/BaseControllerV2.ts Outdated
Comment thread src/BaseControllerV2.ts Outdated
brad-decker
brad-decker previously approved these changes Mar 8, 2021

@brad-decker brad-decker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the removal of base controller subscribe/unsubscribe can happen here or in a follow up. Happy to see this taking shape, and can't wait to use it in the extension :)

brad-decker
brad-decker previously approved these changes Mar 8, 2021

@brad-decker brad-decker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Gudahtt

Gudahtt commented Mar 8, 2021

Copy link
Copy Markdown
Member Author

Thanks for the review @brad-decker ! Unfortunately I've just discovered that I forgot to document all of these methods though 🤦. So I'm gonna push one more commit in a few minutes to address that shortcoming.

@Gudahtt

Gudahtt commented Mar 9, 2021

Copy link
Copy Markdown
Member Author

Alright, all methods should now be documented! This is ready for review again.

brad-decker
brad-decker previously approved these changes Mar 9, 2021

@brad-decker brad-decker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs LGTM

@Gudahtt

Gudahtt commented Mar 9, 2021

Copy link
Copy Markdown
Member Author

It'd be nice to get more feedback on this one before merging since it'll have a large impact upon future controller work, so I've tagged more people for review. No pressure though. I'll leave this open another couple of days, or until it gets another approval or two.

@Gudahtt
Gudahtt force-pushed the controller-messaging branch from c4fb8f4 to c267a31 Compare March 11, 2021 04:14
Gudahtt added 6 commits March 11, 2021 13:21
Adds a controller messaging system, which will be used to facilitate
inter-controller communication. The controller messenger acts as a
message broker, passing actions and events back and forth between
controllers. It is _fully type safe_.

This idea was described in the Controller Messaging System proposal[1].

This controller messenger doesn't yet support attenuation, so it's not
yet possible to restrict which actions and events are interacted with.
That will be coming in a later PR.

[1]: https://www.notion.so/Controller-Messaging-System-617efb02b9e54bd0a0b0e44c6f776d85
The base controller no longer exposes methods to subscribe and
unsubscribe to state changes. Instead all subscriptions and
unsubscriptions are done with the controller messaging system.
This event name matches the naming convention of the event prefix,
which is also camelCase.
JSDoc comments have been added for each method on the controller
messenger instance.

Additionally, the `event` parameter has been renamed to `eventType`,
and the `action` parameter has been renamed to `actionType`. This was
done while adding docs because it made the documentation easier to
understand.
These types were only used internally. We can export them again if and
when that becomes useful.
@Gudahtt
Gudahtt force-pushed the controller-messaging branch from c267a31 to 1671284 Compare March 11, 2021 16:52

@brad-decker brad-decker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants