TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

JavaScript (client-side) Messaging Anti-Patterns

10 点作者 ifandelse大约 13 年前

1 comment

kls大约 13 年前
I tend to treat message passing data as immutable, I think in my time developing applications (almost 20 years now) I have hit a pattern maybe twice where I have needed something to modify the message before other listeners in the sequence receive it, but when they arise they can be a nasty pattern to deal with. It brings order of events to a pattern which for the most part is designed to be unordered. I have developed two patterns to deal with modifying messages when the need arises and I am still not sure which I like better.<p>The first is I clone the message and pass a mutable and immutable copy of the data, this seems to work ok but you still have to ensure order of events, so if the message passing pattern guarantees first in first out, I just make sure the registration sequence of modifying listeners are registered first. It is not bullet proof but it has worked for my needs.<p>The second pattern I have used is a concept of a preprocessor routine, kind of a method that does all the modification before the message event is fired, so I wire the data to the preprocessor and then the preprocessor fires off the message event after it has made it's modification.
评论 #3734844 未加载