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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

The Usefulness of Abstracting Over Time

53 点作者 maxhallinan将近 7 年前

4 条评论

orf将近 7 年前
I get why removing global state is a good thing in general, but here you are replacing it with a whole lot of complexity for not a particularly clear reason. Is tracking the user count with an integer dangerous <i>in this case</i> (Have you run into problems with it)? Is your solution not using global state anyway, just wrapped in a library?<p>All in all, are the abstractions (a bunch of new concepts plus a new library) <i>worth it</i> to just replace an integer?<p><pre><code> function timerFunc() { if (connectionCounter) get results(); } socket.on(&#x27;connect&#x27;, function() { connectCounter++; }); socket.on(&#x27;disconnect&#x27;, function() { connectCounter--; }); </code></pre> The real problem is you want to start and stop the timer when someone connects. Just keep it simple and keep it going, but not doing anything if there is nobody connected, like above.
评论 #17792207 未加载
mpweiher将近 7 年前
Hmm...<p>&quot;The server always asks for new location data, every 30 seconds, even when no one is listening.&quot;<p>...<p>&quot;Our task is to pause the timer when there are no websocket connections and start the timer when a client connects.&quot;<p>That sounds like asking for trouble. Maybe there&#x27;s something I am not understanding, but why not have the timer run continuously and have the timer <i>action</i> check whether it needs to request location data?<p>Yes, that will cause the process to wake up every 30 seconds even if there is no action, but unless circumstances are very special that won&#x27;t be a significant problem.
评论 #17790282 未加载
评论 #17790096 未加载
评论 #17790094 未加载
wilgertvelinga将近 7 年前
Very nice explanation. Gives a good insight how you can &quot;think in observables&quot;. Two small things 1. instead of merging zero$ into connectionClosed$ you can use the startWith() method. 2. Instead of using the head method to pluck the first item of an array you could use array destructuring. (But I can understand that you wouldn&#x27;t do it in this to limit the amount of &quot;new&quot; concepts)
fleitz将近 7 年前
Send a message to a queue asking for refreshed data... ignore messages that occur within a given timeframe.<p>Or put your server in front of a CDN &#x2F; Nginx, set cache headers for 30 seconds ;)