是否有通用的方法来处理大型持久数据结构的更改通知?
首先这个问题的动机:任何使用持久数据结构和 GUI 的人都会遇到这个问题。所以,我的问题是:人们是否只是根据具体情况来解决这个问题,或者他们的库、实用程序、框架是抽象一般情况以使其更容易执行的东西。
我针对的特定语言是 Scala,但我认为这是与持久数据结构相关的普遍问题。
假设您有一个大型数据结构,显示在复杂的 GUI 中,其中包含树、表、属性表等。各种用户或系统操作都会导致数据结构的修改。
是否有处理通知以告诉 gui 自行更新的通用策略?
持久数据结构的有趣想法之一是只需在根之间切换即可处理撤消/重做。这适用于数据,但是是否有一种通用机制可以告诉听众(例如图形用户界面)如果要切换根则发生变化?
我的理解是,它需要是渐进的——我需要知道发生了什么变化。我不能只是告诉一切对 gui 进行完全刷新,因为这可能非常昂贵(并且由于维护 gui 状态,某些控件不能很好地(或根本)处理它)。
First the motivation for this question: anyone who uses persistent data structures and a gui runs into this problem. So, my questions is kind of: do people just work it out on a case by case basis, or are their libraries, utilities, frameworks, something that abstracts the general case to make it easier to do.
The specific language I'm targeting is Scala, but I think this is a general question related to persistent data structures.
Let's say you have a large data structure displayed in a complex gui with trees, tables, property sheets, etc. Various user or system actions result in modifications to the data structure.
Is there a general strategy for handling notifications to tell the gui to update itself?
One of the intriguing ideas with persistent data structures is one could handle undo/redo by just switching between roots. That works for the data, but is there a general mechanism for telling listeners (eg. a gui) about the change if one were to switch roots?
My understanding is that it needs to be incremental--I need to know what changed. I can't just tell everything to do a complete refresh of the gui since that could be very expensive (and some controls don't handle it well (or at all) because of maintaining gui state).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在切换根的同时更新 GUI,因为如果结构确实是持久的,那么结构深处的任何更改都将产生新的根。然而,这将是强制完成的(或者以某种单子构造的方式;我从未在 Haskell 中进行过 GUI 编程)。
例如,如果您的 GUI 代码是命令式/OO 但使用持久的
State
结构:You'd update the GUI at the same time you switch roots, since if the structure is truly persistent, then any change deep down in the structure will incur a new root. That, however, will be done imperatively (or in some kind of monadic construction; I've never done GUI programming in Haskell).
E.g., if your GUI code is imperative/OO but uses a persistent
State
structure:请参阅有关 Scala 中的函数响应式编程的问题。另请参阅 单元菜单 和 有关 FRP 的维基百科文章作为背景。
并阅读论文“使用 Scala.React 弃用观察者模式”: http://lamp .epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf 在 magicduncan 对上述问题的回答中提到。
See this question about Functional Reactive Programming in Scala. And also see the Cells menifesto and the Wikipedia article about FRP for background.
And read the paper "Deprecating Observer Pattern using Scala.React": http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf mentioned on an answer by magicduncan on the above SO question.