【问题标题】:Is there a object to object data binding and event framework in javascript/typescript?javascript/typescript 中是否存在对象数据绑定和事件框架的对象?
【发布时间】:2017-01-11 19:21:02
【问题描述】:

喜欢这个:https://github.com/errisy/bindable/blob/master/README.md

使用简单的打字稿装饰器设置数据绑定。

具有路径更改检测的绑定和事件中的弱引用。

所有绑定和事件都保存为“弱引用”ITTrigger。一旦 ITrigger.target 设置为 undefined,调用者将删除 ITrigger。

当 A.property 绑定到(或 A.method 监听)A.branch.value 时,如果 A.branch 发生变化,则绑定主机和监听器都可以检测到路径变化。他们会将之前的 ITrigger 的 ITrigger.target 设置为 undefined 以禁用之前的绑定并监听,然后设置新的绑定并监听新分配的分支。

@obs.bindable 
class Person {
    @obs.property
    public Name: string;
    @obs
      .bind(()=>Person.prototyope.Name.FirstName)
      .before(()=>Person.prototype.beforeFirstNameChange)
      .after(()=>Person.prototype.FirstNameChanged)
      .property
    public FirstName: string;
    @obs.event
    public beforeFirstNameChange = () => {
        console.log('before first name is changed.');
    }
    @obs.event
    public FirstNameChanged = () => {
        console.log('first name is changed.');
    }
}
@obs.bindable
class Name{
    @obs.property
    public Surname: string;
    @obs.property
    public FirstName: string;
}

let p = new Person();
p.FirstName = 'Jack'; // p.Name.FirstName will change as well.

【问题讨论】:

  • 虽然这个框架可能不错,但这不是宣传它的地方。
  • 在这里提出和回答您自己的问题很好,但是 a) 答案需要作为答案发布,而不是问题的一部分,并且 b) 它们必须符合通常的质量要求跨度>

标签: javascript wpf typescript binding


【解决方案1】:

有不少。我目前最喜欢的:https://github.com/mobxjs/mobx,它支持透明反应式编程。

其他

那里有许多不透明的选项,例如任何像 rxjs 这样的 observables。还有一个旧的是 knockoutjs,但它绑定到自己的 UI 编程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 2010-11-30
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多