Remove Evt.asPostable(evt) #39
Replies: 4 comments
-
Thanks @andreas-wagner, Thanks for the feedback. I am not happy about import { Evt } from "evt";
import type { NonPostableEvt } from "evt";
class Example {
#evtMsg = Evt.create<string>();
readonly evtMsg= Evt.asNonPostable(this.#evtMsg);
constructor() {}
} This is nice! Using |
Beta Was this translation helpful? Give feedback.
-
After futher consideration I think it is best that if import { Evt } from "evt";
import type { NonPostableEvt } from "evt";
class Example {
#evtMsg = Evt.create<string>();
readonly evtMsg= Evt.asNonPostable(this.#evtMsg.pipe());
constructor() {}
} This way even if a user try to
So, I agree to remove |
Beta Was this translation helpful? Give feedback.
-
I have updated the documentation: |
Beta Was this translation helpful? Give feedback.
-
And I released 2.4 where |
Beta Was this translation helpful? Give feedback.
-
What is the problem?
Let's see the docs
..and the source-code
This means everyone can post on any Evt instance, being the creator or not.
Let's assume we have a service providing some evt's, and the service is controlled by some part of the application.
This part of the application gives these evt's to other parts.
Example:
A file logger has to close a file handle on
evtServiceShutdown
, but the logger is part of some other external module.That external module is not used all the time and instantiated and destroyed multiple times during the services lifetime.
Maybe it's only used once a day to synchronize with something.
Now if the logger posts on the
evtServiceShutdown
the whole service shuts down. This is bad. It should not have any ability (in real js, not ts) to post toevtServiceShutdown
.Proposal
Create a fully functional
Evt
instance first, and from that create a newNonPostableEvt
instance that can only listen to it's parent(s) and does not have any post method.Somehow deno std logger comes to mind, with separated handlers and formatters and the logger instance being modular.
Beta Was this translation helpful? Give feedback.
All reactions