Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early-stage JS messaging refactoring #9

Conversation

jamierumbelow
Copy link
Contributor

This PR starts to standardise the messaging format between the different JS files, with the goal of being able to validate and type messages from cradle to grave, from JS to Swift and back again.

The core idea is that all JS files communicate with the following object:

type Message = { destination: "background" | "content" | "popup";  method: string; params: any; sessionId: string; }

destination is used to multiplex the browser runtime events channel, and permit more generic method names. method is currently general-purpose, but will later be typed, ditto params. sessionId is currently unused.

It also:

  • simplifies the view rendering logic
  • removes much of the global state from background, content and popup, preferring a more injected, localised and functional approach
  • adds tab-specific sessionId generation, which is stored in and read from localStorage
  • adds a lot of logging to the frontend code
  • adds a very rough loading state for initial popup load

My approach here has been to try to build in an 'invisible' way, so the extension should work mostly as it did before. Signing wasn't working for me before, so I've been unable to test it properly.

Explicitly not included in this PR:

  • TypeScript
  • Reusability of messaging primatives between JS files (ie there is some duplication right now)
  • Unit testing of messaging primatives
  • Standardisation of the JS <-> Swift interface
  • Session-specific network connections

The above list provides a pretty good roadmap for what I'll be working on this week :)

starting to standardise the messaging format between the different JS
files, with the goal of being able to validate and type messages from
issuance to read in the Swift extension.

this commit also simplifies the view rendering logic and removes much of
the global state from background, content and popup, preferring a more
injected, localised and functional approach.
@ronaldmannak
Copy link
Contributor

@natclark can you take a look at the commit since all changes are in the JS part?

@jamierumbelow
Copy link
Contributor Author

Holding in draft state until #9 is merged, will update this branch then.

@jamierumbelow
Copy link
Contributor Author

Superseded by #13.

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.

None yet

2 participants