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

Closing a view then showing it does not re-bind triggers! #622

Closed
farias-r7 opened this issue May 23, 2013 · 6 comments
Closed

Closing a view then showing it does not re-bind triggers! #622

farias-r7 opened this issue May 23, 2013 · 6 comments

Comments

@farias-r7
Copy link

Let's say you have a layout view and show the following view for some random region. Everything works as expected, and when you call close() on the region with this view all the event bindings are removed as expected.

Here's the problem. If you call close() on the region, then show() with the same instance of the view, the triggers no longer work! The view still re-renders and displays as expected however.

You would assume that if onRender is called on the re-render that the @on event binding call would still work.

Apologies the following snippet is in Coffeescript, but results in the same issue.

class SomeItemView extends Backbone.Marionette.ItemView
   template: HandlebarsTemplate['/some/template']

   triggers:
      'click' : 'item:clicked'

   onRender: =>
      @on('item:clicked', @_some_callback)

   _some_callback: ->
      console.log("event handled!")
@farias-r7
Copy link
Author

The work around for me was to call delegateEvents() on the view before I call .show() when I want to redisplay the view in the layout's region. Is this the expected behavior?

Or should I submit a pull request with delegateEvents() being called on the view when .show() is called in a layout region?

You would think close() and show() would automatically unbind and bind events respectively.

@quangv
Copy link

quangv commented May 30, 2013

Yeh same thing for me... had to do something like...

onShow : -> @delegateEvents()

onClose it undelegateEvents wouldn't it make sense automatically Marionette delegateEvents onShow ?

@farias-r7
Copy link
Author

Looks like this is a DUP. #724

Looks like there are multiple issues open for this.

@eth0lo
Copy link
Contributor

eth0lo commented Nov 20, 2013

The way think about marionette's views, is that they are disposable, which means you have to recreate them if you need them back; for those cases you want to keep your data somewhere so you can create a new instance an put it back on the view

@gaydenko
Copy link

Recreating a new view and filling it in with old data is rather noticeable work. Here the issue resolved just with a single boolean flag: http://barc.github.io/backbone.giraffe/menuExample.html

@samccone
Copy link
Member

Yup look at #724

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

No branches or pull requests

5 participants