-
Notifications
You must be signed in to change notification settings - Fork 39
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
Refactor Broadcast allowing for customizable transport stream decorators #59
Comments
I am thinking the Core Centric approach sounds better too. One thing I'm not quite understanding is... I'm guessing that that question is outside the scope of what you're looking at here, but I wanted to ask incase I'm not fully appreciating it! Thanks! |
Syntax wise the decorator defines the syntax. If you don't like the syntax your decorator uses you'd write a translating decorator that converts from one syntax to another and put it before the coloring decorator in the list. For example you're using |
I have a branch implemeneting this feature here: https://github.com/Sakeran/core/tree/transport-decorators
socket.write() conventionThis one is probably more important than the decorators themselves. The current standard when calling a Example:
This gives us a few advantages:
I may be overqualifying this point a bit, but it is a powerful change. It also doesn't break either of the existing networking bundles like I thought it might (websockets doesn't use it, telnet falls back to utf8), so migration isn't too much of an issue for anyone using those. TransportDecoratorRegistryAs stated above, Decorating a TransportStream works as specified, with BroadcastI added a new static function: ( A fair number of Either way, it's not hard move the affected utility functions to wherever EventUtilOne nice thing about decorators is that input events no longer need special consideration for coloration to work. I just stripped out the sty parsing for now, but nothing in this module seems strictly necessary at this point, and is mostly still around so I didn't have to rework the example input-events. I may be missing a few other places in core where sty syntax is used by default - the |
Additionally, here's an example of what a https://gist.github.com/Sakeran/5a1b8781ce0eb3ac6ad00957f4f99999 |
(note: I debated opening a separate ticket for this so please let me know if that would be more appropriate) I'd like to suggest that the entire |
The
sty
coloration library is currently hard coded inside theBroadcast
class. BecauseChannel
is a core class which usesBroadcast
that makescore
opinionated about how color should work. This makes it impossible to customize if you:sty
syntaxMy high level concept is to create a system of customizable
StreamDecorators
that can be attached toTransportStreams
in such a a way that a developer wouldn't have to modify core code AND wouldn't have to modify the transport bundle's (liketelnet-networking
code).The difficulty is that
TransportStream
types aren't registered anywhere in the way thatEntityLoaders
are registered. This means there is currently no good central place to create theStream+Decorators
bindings.Possible solutions
Bundle-centric
In this approach the transport bundle (e.g.,
telnet-networking
) would entirely be in charge of this: they'd handle the initialization, customization, and management of decorators.Pros
Cons
Core-centric
In this approach there would be a base
TransportDecorator
class in core in the same way there is a baseTransportStream
class. Additionally the core would have to decide upon and own the configuration/binding strategy for Stream+DecoratorsPros
Cons
For me the core-centric approach seems like the obvious choice. The pieces of that puzzle look something like this:
TransportStream
TransportStream
will need some way to identify themselves in such a way that configuration could link a transport stream to its decorators, my initial idea is that the class should get a new identifier getter, for example:TransportDecoratorRegistry
My idea for how to actually bind decorators to a stream involves creating a new
TransportDecoratorRegistry
. This class will be in charge of holding the configuration fromranvier.json
which will look similar toDataLoader
configuration:This is really verbose with all the configs but in practice it will look more like this:
To actually facilitate the usage of these decorators
TransportDecoratorRegistry
will have adecorate(TransportStream streamConstructor)
method. This method will be used by transport bundle developers which means if a bundle developer so chooses they can not allow applying decorators:Writing a decorator
To write a new decorator, similar to DataLoader, there is no base class to extend. Instead you just need to follow the prescribed API:
This class can either be an npm module or just a local file.
Changes for transport bundle devs
All that is in core. For the actual transport bundle developer they would write the following:
The text was updated successfully, but these errors were encountered: