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

Preparation for adding a service manager to puter.js #810

Merged
merged 3 commits into from
Oct 18, 2024

Conversation

KernelDeimos
Copy link
Contributor

@KernelDeimos KernelDeimos commented Oct 18, 2024

The service pattern has proven incredibly useful. This implements a new services registry for later use in puter.js, putting a lot of common functionality into putility where it can also be used in backend. Also in this PR is an implementation of a generic way to provide listenable events on a class (called "topics"), that lack of which has been a pain point up until now.

These additions in putility also further established how traits are used. Using traits instead of imaginary interfaces will improve readability (specifically the ability to find what files/classes are involved in a particular behavior) as well as make name collisions with methods impossible. .mixin() is also now provided by TraitsFeature, which is effectively an implementation of mixins without the drawback of name collisions because it's working on top of traits.

The ServiceManager will replace manual management of services within
initgui, and will also be used within puter.js. Eventually Puter's
backend might use this instead of the existing Container class, although
this will be a large change that needs to be done incrementally.

The difference between ServiceManager and Container is the logic behind
when initialization occurs. Rather than have all services initialized at
once when Container's init() method is called, services are initialized
as soon as their dependencies have been initialized.
Dispatching and listening to events is non-trivial. The apparent
triviality is in implementing a list of listeners and calling them. The
non-triviality is in the nature of what happens to a system when it has
multiple different interfaces to register listeners and publish events.

This commit adds TopicsFeature, which allows any class extending
AdvancedBase to declare topics. A topic is a simple pub/sub channel.
TopicsFeature will manage the state of listeners so the class doesn't
need to. A GC-friendly mechanism for detaching listeners is also provided.
@KernelDeimos KernelDeimos merged commit 7922314 into main Oct 18, 2024
4 checks passed
@KernelDeimos KernelDeimos deleted the eric/prep-for-puterjs-services branch November 28, 2024 19:28
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.

1 participant