Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose layer tree node event listeners. #357

Merged
merged 1 commit into from
Sep 2, 2015

Conversation

bentrm
Copy link
Member

@bentrm bentrm commented May 12, 2015

I think there are some dangling event listeners associated with the layer node. I hope to fix this with this PR.

As far as I can tell, there is no reasonable way to hook into the destruction of the LayerTreeModel of the LayerNode to fix this so I used the maps 'removelayer' event. 'preremovelayer' is not an option as other listeners outside of this scope may cancel removing the layer. That's also the reason for caching a reference to the actual map. When 'removelayer' is called the layers map property is already lost.

@marcjansen
Copy link
Member

Any chance you can add some tests? On first glance this looks fine. Also, is #358 a replacement?

@chrismayer chrismayer mentioned this pull request May 18, 2015
9 tasks
@bentrm
Copy link
Member Author

bentrm commented May 18, 2015

There are no explicit tests for GeoExt.tree.LayerNode right now so I was a bit hesitant and deferred it. I'm happy to help but will not have time to look into this before the weekend.

var target = this.target,
layer = target.get('layer')

if (evt.layer !== layer) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also use curly braces around one liners.

@marcjansen
Copy link
Member

As far as I can tell, there is no reasonable way to hook into the destruction of the LayerTreeModel of the LayerNode to fix this …

Have you tried (untested):

// …
init: function(target) {
    this.target = target;
    this.target.addListener('beforedestroy', this.cleanupMethod, this);
    // …
}
// …

Except for this and two other comments this is good to go.

@bentrm
Copy link
Member Author

bentrm commented May 19, 2015

Yes, I tried that. this.target is an instance of GeoExt.data.LayerTreeModel which is an Ext.data.Model. The only event that is advertised seems to be idchanged. Furthermore, I tried to destroy the LayerNode plugin by hooking into the destroy method of the LayerTreeModel but it is never called as "destroy" of Ext.data.Model is used to delete the record which seems not to be the case here.
I think the proposed solution is borderline hackish but I'm out of ideas.

@marcjansen
Copy link
Member

I will give my OK for a merge if we add a big TODO somewhere and maybe even an issue as the approach seems more than hackish to me.

Nonetheless the result is better than what we had before, so plus one for merging this once it is updated with a big TODO.

Can you update this @bentrm?

@bentrm
Copy link
Member Author

bentrm commented Aug 27, 2015

as the approach seems more than hackish to me.

I agree, absolutely. Will add a TODO.

@chrismayer
Copy link
Contributor

Hi guys,
any news on this? thanks!

@bentrm
Copy link
Member Author

bentrm commented Sep 2, 2015

Promise to take care of this this afternoon. Sorry about that, I know you want to ship on 4th. :shipit:

@bentrm
Copy link
Member Author

bentrm commented Sep 2, 2015

I amended the last commit to include TODOs hope you're ok with that. Thanks for your patience.

@marcjansen
Copy link
Member

👍 thanks!

marcjansen added a commit that referenced this pull request Sep 2, 2015
Dispose layer tree node event listeners.
@marcjansen marcjansen merged commit a9efeb1 into geoext:master Sep 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants