简体   繁体   English

从聚合物元素选择性地发布属性变化

[英]Publishing property changes from polymer element selectively

I am tying polymer elements in with an existing framework and I am looking for a way to publish events to my framework when certain properties are set on my elements, but only when they are set from a source other then my framework. 我将聚合物元素与现有框架联系在一起,并且正在寻找一种方法,当在元素上设置了某些属性时(但仅当它们是从其他来源而不是从框架中设置时)将事件发布到框架。

For example, I have a custom input element with a "caption" attribute. 例如,我有一个带有“标题”属性的自定义输入元素。 If data binding inside my elements or some source other than my framework sets the caption property on my control, I want an event published to my framework informing it that the caption property changed, but if my framework sets the caption property, I do not want to publish the event. 如果数据绑定到我的元素或除框架之外的其他源中,则在控件上设置了caption属性,我希望将一个事件发布到我的框架,以通知其caption属性已更改,但是如果我的框架设置了caption属性,则我不想发布事件。

I currently publishing these events in an observe block. 我目前将这些事件发布在一个观察块中。 I have a function on my elements called setFromExternalModel(prop, value) that I use to set the value of a property from my framework. 我在元素上有一个名为setFromExternalModel(prop,value)的函数,该函数用于设置框架中属性的值。 If there were some way for me to pass data from this function on to the observe block, I could prevent the event from being published, but I haven't been able to come up with an elegant way to do this. 如果我有某种方法可以将数据从该函数传递到observe块,则可以阻止事件的发布,但是我无法提出一种优雅的方法来实现。

Thoughts? 有什么想法吗?

Why is it important to not fire events if your framework changes a property? 如果您的框架更改了属性,那么不触发事件为什么很重要? It is much less complicated to treat all property changes the same way. 以相同的方式处理所有属性更改要简单得多。

Polymer's core and paper elements have no concept of framework/user data changes, and we haven't thought of any use cases where this would be important. Polymer的核心和书面元素没有框架/用户数据更改的概念,并且我们还没有想到任何重要的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM