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

Reassess design pattern: Pub/Sub doesn't make sense in the context of a web-worker or small plugin #39

Open
gingerchew opened this issue Oct 21, 2020 · 0 comments · May be fixed by #40
Labels
enhancement New feature or request
Milestone

Comments

@gingerchew
Copy link
Member

While the Pub/Sub model is nice, especially when written with such a thin wrapper, it is useless when not exposed outside the plugin. I can't find a justification for exposing the Pub/Sub given what it currently does, so it is probably best to scrap it and move on to a different model.

The next step is to find a different design pattern to follow. The design pattern needs the following:

  • Can work well or be adapted to work with Dedicated Workers
  • Handles multiple forms/objects (takes advantage of Proxy?)
  • Reduces complexity before it increases it
  • Is easy to pick up for new comers

Singleton speaks to me, as it could look something like this:

class WeHateCaptchas {
	constructor() {
		this.instances = new WeakMap();
	}

	getInstance(form) {
		// ... do object get stuffs
	}
}

This is appealing as it would only be one class to manage, and there would be no need to create multiple objects for each form.

The form would act as the key in the WeakMap, with the value being an object holding the worker. Messaging between the worker thread and the main could be handled with a Proxy object that is also stored in the WeakMap. This adds a layer of complexity that is not needed though.

There are other details to iron out with this pattern, such as DOM manipulation, messaging, and more.

@gingerchew gingerchew added the enhancement New feature or request label Oct 21, 2020
@gingerchew gingerchew added this to the 2.0 milestone Oct 21, 2020
@gingerchew gingerchew linked a pull request Oct 22, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant