# Is there a way to listen to node changes?

**URL:** <https://forums.creativeclouddeveloper.com/t/is-there-a-way-to-listen-to-node-changes/3570>\
**Category:** Adobe XD\
**Created:** [August 31, 2021, 12:25pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-a-way-to-listen-to-node-changes/3570 "2021-08-31T12:25:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adinu](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@adinu](https://forums.creativeclouddeveloper.com/u/adinu)\
**Post date:** [August 31, 2021, 12:25pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-a-way-to-listen-to-node-changes/3570/1 "2021-08-31T12:25:27Z")

</div>

Let’s say i have a rectangle, and the user changes it’s position/size in xd. is there a way my plugin will know about this change and handle stuff?

---

<div class="post-metadata">

**Author:** ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)\
**Post date:** [September 1, 2021, 3:12pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-a-way-to-listen-to-node-changes/3570/2 "2021-09-01T15:12:09Z")

</div>

For panel plugins, the `update` lifecycle hook gets triggered whenever the document changes ([https://www.adobe.io/xd/uxp/develop/tutorials/quick-start-panel/#update-your-ui](https://www.adobe.io/xd/uxp/develop/tutorials/quick-start-panel/#update-your-ui)). Unfortunately, it doesn’t provide any details about what in the document has changed.

What you could do would be to, on every `update` call, go through the document, “save” its state in a variable, and then compare the document with the stored “previous” state in the `update` hook.

The thing is that `update` should be as performant as possible (since, as you can imagine, if your plugin executes complex code on every little edit the user does, this can impact the performance).

All in all, we can therefore say that yes, it is possible, but it does have its limitations. What probably wouldn’t be a big problem is to monitor a limited, “pre-defined” set of layers for changes of specific properties, which should be relatively performant to compare. I don’t think it would be a good idea to compare every single “property” of the document on every update, though.

Also, keep in mind that updates to the document don’t necesserily mean that you can detect this change. E.g., if another plugin’s `pluginData` field of a `SceneNode` gets updated, this is an update that you can’t detect. Thus, there can also be “empty” updates.

I hope this helps (even though it’s probably not as easy as you might have been hoping for),  
Best,  
Pablo

---

<div class="post-metadata">

**Author:** ![adinu](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@adinu](https://forums.creativeclouddeveloper.com/u/adinu)\
**Post date:** [September 5, 2021, 12:28pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-a-way-to-listen-to-node-changes/3570/3 "2021-09-05T12:28:17Z")

</div>

thanks so much for the answer. is there a way not to allow the user to change the size of an element, but be able to move it in the artboard?

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [September 7, 2021, 5:04pm UTC](https://forums.creativeclouddeveloper.com/t/is-there-a-way-to-listen-to-node-changes/3570/4 "2021-09-07T17:04:47Z")

</div>

No; plugins cannot restrict the sizes of elements. You could have a command that fixes it up after the fact, but not while the element is being edited.
