设置元素 属性 时未触发聚合物 "property-changed" 事件
Polymer "property-changed" event not fired when element property is set
我有一个 Polymer 元素 (cw-app
) 属性 声明如下:
test: {
type: String,
notify: true,
value: 'default test value'
}
如您所见,它的声明默认值为 default test value
。
最初,当元素像这样添加到页面时:<cw-app></cw-app>
相应的 test-changed
事件被触发。
但是,如果我添加元素并像这样为 属性 设置值:<cw-app test="new value"></cw-app>
,那么最初不会触发 test-changed
事件。
这是期望的行为吗?是否有任何记录?
我会说这是预期的行为:
在第一种情况下,test
的值从 null
(未设置 test
属性)更改为 "default test value"
,因此 已更改 事件已触发。
在第二种情况下,值在创建时设置为 "new value"
。它没有改变,所以没有 changed 事件。
请参阅 GitHub 上关于 Polymer issue page 的讨论:
If you declare <x-foo id="foo" value="foo"></x-foo>
the value foo will be assumed to be coming 'from above', t.i. from a user of the element. During config phase Polymer will not echo such data changes upwards. (Assuming the producer of the value/user of the element already has knowledge of this change.)
On the other side, if you <x-foo id="bar"></x-foo>
the default value
will propagate upwards. For the same reasons, x-foo produced this
value, and the user of x-foo has otherwise no knowledge about this.
T.i. the default value is not coming from above(, but from x-foo).
我有一个 Polymer 元素 (cw-app
) 属性 声明如下:
test: {
type: String,
notify: true,
value: 'default test value'
}
如您所见,它的声明默认值为 default test value
。
最初,当元素像这样添加到页面时:<cw-app></cw-app>
相应的 test-changed
事件被触发。
但是,如果我添加元素并像这样为 属性 设置值:<cw-app test="new value"></cw-app>
,那么最初不会触发 test-changed
事件。
这是期望的行为吗?是否有任何记录?
我会说这是预期的行为:
在第一种情况下,
test
的值从null
(未设置test
属性)更改为"default test value"
,因此 已更改 事件已触发。在第二种情况下,值在创建时设置为
"new value"
。它没有改变,所以没有 changed 事件。
请参阅 GitHub 上关于 Polymer issue page 的讨论:
If you declare
<x-foo id="foo" value="foo"></x-foo>
the value foo will be assumed to be coming 'from above', t.i. from a user of the element. During config phase Polymer will not echo such data changes upwards. (Assuming the producer of the value/user of the element already has knowledge of this change.)On the other side, if you
<x-foo id="bar"></x-foo>
the default value will propagate upwards. For the same reasons, x-foo produced this value, and the user of x-foo has otherwise no knowledge about this. T.i. the default value is not coming from above(, but from x-foo).