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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Oops.js

23 点作者 ent1019 个月前

4 条评论

coolhand21209 个月前
After reviewing the ~600 lines of code, I have to ask what about this undo&#x2F;redo manager is &quot;advanced&quot;? This seems like a naive implementation of a snapshot collection that is selected via array index. It&#x27;s not event sourcing, OT or CRDT. With every event, the entire object is serialized and put into the heap. I can&#x27;t even imagine what this does for performance when you deal with any object of significant size. What if you wanted to do something like type? Thousands of copies of the same thing.<p>Why not <a href="https:&#x2F;&#x2F;github.com&#x2F;yjs&#x2F;yjs">https:&#x2F;&#x2F;github.com&#x2F;yjs&#x2F;yjs</a>? Event sourcing is cool. Operational transformation is awesome. But Conflict Free Replicated Data Types are king.<p>Read up on event sourcing, OT and CRDT. If you&#x27;re not using one of these patterns and you haven&#x27;t come up with something better you&#x27;re creating foot guns for the world to shoot themselves with.<p>I apologize for being so harsh. I write undo&#x2F;redo on JS&#x2F;web quite a lot and this is going down a dark path.<p>Also, you should not put your dist directory in your repo. It should be a deployed artifact connected to a tagged release - or even better keep it in NPM where it belongs.
unconed9 个月前
Undo&#x2F;redo seems like one of those problems where the knowledge of how to actually do it properly seems lost. People just dig up the supposedly &#x27;solved&#x27; ancient solution and then cargo cult it.<p>So you end up with something like this, which looks like a polished and approachable library of a &quot;standard&quot; command pattern. But if you use patterns modeled after single user &#x2F; local-only apps, you will code yourself into a corner.<p>i.e. In a multiplayer environment, the command pattern is not what you want, because every user has to be able to undo only their own local changes. This means rebasing the local undo&#x2F;redo history on top of remote changes. Reverting an operation might not result in the same state you had when you performed the action. If the logic of how the command works is frozen inside the code inside a class, no other code can operate on it.<p>I&#x27;ve had much more success with a more functional method based on diffs and patches, i.e. mutations as data. For convenience as a dev, you want to be able to express local changes in a non-reversible way, without the undo&#x2F;redo nature of the app forcing you to rewrite every change as a non-composable command.<p>You can then convert these into reversible changes automatically (e.g. OTs), which you can put in your undo&#x2F;redo history, and which can be rebased over each other.<p>I&#x27;ve been trying to lone-star adding proper undo&#x2F;redo systems to the apps I work on for years, and it always runs headfirst into the fact that the other devs—especially back-end devs—are not able or willing to admit that most everything they know about building applications is wrong and has to be thrown out.<p>These people of course also swear by Git and would refuse to do their jobs without it.
评论 #41219720 未加载
m0rde9 个月前
Was just thinking about the lack of undo&#x2F;redo in a complex web app we&#x27;re building involving ling-running APIs and DB transactions. What are some other undo&#x2F;redo TypeScript libraries out there.<p>For Oops particularly, I think TS interfaces for commands would help quite or lot here. Or maybe even annotations or decorators?
评论 #41215974 未加载
评论 #41216606 未加载
danjl9 个月前
I like the C++-style, class-based implementation. We need more JS modules like this. Zero dependencies. No async code. No callbacks. No HTML.