数据绑定的主要示例

发布于 2024-09-18 11:46:59 字数 1052 浏览 4 评论 0原文

我正在 JavaScript 中实现一个准系统框架,它只提供对象之间的数据绑定。数据绑定可以是单向或双向的,并且可能在某个属性上绑定多个对象。有多种适用于各种语言的数据绑定解决方案,我正在努力了解最好的方案,以便从中挑选功能集。到目前为止,我已经研究了以下提供绑定的框架:

请随意编辑问题并添加支持绑定的其他框架(如果缺少)。

您认为哪些数据绑定功能在您选择的各自框架中非常有价值?该框架的目标是消除尽可能多的粘合代码。另外,有没有关于这个主题的研究论文可供我研究?

I am implementing a barebones framework in JavaScript that just provides data-binding between objects. The data-binding can either be one-way or two-way, and potentially have multiple objects bound on some property. There are several data-binding solutions available for various languages and I am trying to get a good idea of the best of all worlds to cherry pick the feature set from. So far I have researched the following frameworks that provide bindings:

Please feel free to edit the question and add additional frameworks that support binding if they are missing.

What data-binding features do you find extremely valuable in your respective framework of choice? The objective of this framework will be to eliminate as much of the glue code as humanly possible. Also, are there any research papers on the topic that I can munch on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最后的乘客 2024-09-25 11:46:59

还要看看其中最古老的工具包之一:Tk 工具包(通常与 tcl 相关,但也有其他语言版本)。在 Tk 中,更新 GUI 中的值通常通过简单地更新变量来完成:

set foo "Hello" ;# just a simple variable

# Create a label widget displaying "Hello"
pack [label .l -textvariable foo]

# Now change "Hello" to "Goodbye"
set foo "Goodbye"

或者更复杂的示例,10 秒倒计时小部件:

set countdown 10
pack [label .count -textvariable countdown]

proc tick {} {
    incr countdown -1
    if {$countdown > 0} {
        after 1000 tick
    }
}
tick

实际上,该功能是通过跟踪命令从 tcl 语言本身派生出来的:

# A simple auto-incrementing variable:

set foo 0
proc autoIncrement {varname args} {
    incr $varname
}
trace add variable foo read {autoIncrement foo}

# now every time foo is read it increments itself by 1

当然,您可以不要期望所有语言都具有此功能。不过,您可以通过轮询来模拟它,也许可以使用 setInterval() 。 Tk 的做法对我来说感觉最自然。

Also look at one of the oldest of them all: the Tk toolkit (usually associated with tcl but is also available in other languages). In Tk updating a value in the GUI is typically done by simply updating a variable:

set foo "Hello" ;# just a simple variable

# Create a label widget displaying "Hello"
pack [label .l -textvariable foo]

# Now change "Hello" to "Goodbye"
set foo "Goodbye"

Or a more involved example, a 10 second countdown widget:

set countdown 10
pack [label .count -textvariable countdown]

proc tick {} {
    incr countdown -1
    if {$countdown > 0} {
        after 1000 tick
    }
}
tick

Actually, the feature is derived from the tcl language itself via the trace command:

# A simple auto-incrementing variable:

set foo 0
proc autoIncrement {varname args} {
    incr $varname
}
trace add variable foo read {autoIncrement foo}

# now every time foo is read it increments itself by 1

Of course, you can't expect all languages to have this feature. You can sort of emulate it by polling though, using setInterval() perhaps. The way Tk does it feels most natural to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文