# JSViewer.onSizeChanged

**URL:** <https://community.datagrok.ai/t/jsviewer-onsizechanged/275>\
**Category:** Issues\
**Created:** [August 15, 2020, 9:30am UTC](https://community.datagrok.ai/t/jsviewer-onsizechanged/275 "2020-08-15T09:30:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexander.shevnin](https://community.datagrok.ai/user_avatar/community.datagrok.ai/alexander.shevnin/32/68_2.png) [@alexander.shevnin](https://community.datagrok.ai/u/alexander.shevnin)\
**Post date:** [August 15, 2020, 9:30am UTC](https://community.datagrok.ai/t/jsviewer-onsizechanged/275/1 "2020-08-15T09:30:44Z")

</div>

`onSizeChanged` method doesn’t seem to be called when adjusting viewer is closed.

 ![image](https://community.datagrok.ai/uploads/default/original/1X/f489f53ca3746a3b981a2bafb0a5ffa67bcf28fe.png) - if I close bottom right viewer, I’d expect top right viewer to be notified so it can take more space.

---

<div class="post-metadata">

**Author:** ![skalkin](https://community.datagrok.ai/user_avatar/community.datagrok.ai/skalkin/32/5_2.png) [@skalkin](https://community.datagrok.ai/u/skalkin)\
**Post date:** [August 16, 2020, 2:08pm UTC](https://community.datagrok.ai/t/jsviewer-onsizechanged/275/2 "2020-08-16T14:08:54Z")

</div>

Thanks for bringing our attention to that. We have decided to change the size notification mechanism in favor of a more flexible Observable, also internally we use ResizeObserver instead of size polling like we did previously. This resulted in one breaking change, the onSizeChanged now being a property that returns Observable. Here is how to use it (Leaflet viewer is already doing that: [https://github.com/datagrok-ai/public/blob/master/packages/Leaflet/leaflet/leaflet\_viewer.js#L17](https://github.com/datagrok-ai/public/blob/master/packages/Leaflet/leaflet/leaflet_viewer.js#L17))

```
this.onSizeChanged.subscribe((_) => this.map.invalidateSize());
```

---

<div class="post-metadata">

**Author:** ![dpetrov.datagrok.ai](https://community.datagrok.ai/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@dpetrov.datagrok.ai](https://community.datagrok.ai/u/dpetrov.datagrok.ai)\
**Post date:** [January 26, 2021, 1:32am UTC](https://community.datagrok.ai/t/jsviewer-onsizechanged/275/3 "2021-01-26T01:32:41Z")

</div>

The OnSize event seems to never be broadcasted. Neither when I open, close, or resize the viewer with the mouse.

class SomeViewer extends DG.JsViewer {

```
constructor() {
    super();

   this.onSizeChanged.subscribe((_) =>alert("Resized"));
}}
```

---

<div class="post-metadata">

**Author:** ![dpetrov.datagrok.ai](https://community.datagrok.ai/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@dpetrov.datagrok.ai](https://community.datagrok.ai/u/dpetrov.datagrok.ai)\
**Post date:** [January 26, 2021, 1:53am UTC](https://community.datagrok.ai/t/jsviewer-onsizechanged/275/4 "2021-01-26T01:53:41Z")

</div>

It works when the subscription is made through the UI class  
ui.onSizeChanged(this.root).subscribe((\_) =\> alert(“Resized”));

---

<div class="post-metadata">

**Author:** ![skalkin](https://community.datagrok.ai/user_avatar/community.datagrok.ai/skalkin/32/5_2.png) [@skalkin](https://community.datagrok.ai/u/skalkin)\
**Post date:** [January 26, 2021, 1:12pm UTC](https://community.datagrok.ai/t/jsviewer-onsizechanged/275/5 "2021-01-26T13:12:38Z")

</div>

Indeed, that was a breaking change we have introduced about a month ago, apologies for not announcing it properly - we thought we’ve adjusted all the code but apparently not 🙂 We got rid of the ViewerBase’s onSizeChanged in favor of the more universal ui.onSizeChanged(element), as the latter could be used in any context.
