【发布时间】: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