Ticket #2531689 (closed enhancement)

Reporter


Evan Culver
Opened: 01/23/12
Last modified: 05/10/12
Status: closed
Type: enhancement
Resolution: fixed

Owner


Ryan Grove
Target Release: 3.5.0
Priority: P3 (normal)
Summary: Y.View should not remove container when destroyed
Description:

Currently, Y.View removes its container by default when calling `destroy`. This is a little counter-intuitive considering it assumes that the view would have created the node in the first place. For
most cases, this is valid, but there are some cases where very dumb views don't always render their container and thus when destroyed, can never rebuild their state later.

For me, my use case is a dumb view, whose container has a non-trivial subtree that I want to bind events within when the view is instantiated. If I ever destroy this view, I can never rebind without
re-rendering this entire view's template, which in this case seems like a little much considering I just want to add functionality to an already existing DOM structure.

This really becomes a pain when writing tests and calling `destroy` via `tearDown`.

As discussed in IRC, it seems that the destroy should behave like Y.Model's destroy. Something like destroy({delete: true}) which would optionally remove the container if told to explicitly.

Type: enhancement Observed in Version: development master
Component: App Framework Severity: S3 (normal)
Assigned To: Ryan Grove Target Release: 3.5.0
Location: Priority: P3 (normal)
Tags: view, destroy, container Relates To:
Browsers: All
URL: https://gist.github.com/1664905
Test Information:

Change History

Ryan Grove

YUI Developer

Posted: 01/23/12
  • milestone changed to 3.5.0
  • priority changed to P3 (normal)
  • status changed from new to accepted

Unless someone objects (Eric?) I'll plan to have View not remove containers by default, and remove them if {delete: true} is passed to destroy().

Ryan Grove

YUI Developer

Posted: 01/23/12
  • estimated changed from 0 to 0.3
  • remaining changed from 0 to 0.3
  • sprint changed to sprint 3

Eric Ferraiuolo

YUI Developer

Posted: 01/23/12

This idea sounds good. But I do not like `{delete: true}` because `delete` is a reserved word and you have to remember to quote it, therefore it is highly error prone. I'd prefer `destroy({remove: true})` or `destroy(true)`.

Ryan Grove

YUI Developer

Posted: 01/23/12

It was mentioned in IRC that `destroy(true)` could be confusing since it would behave differently from Y.Node's `destroy(true)` (it's also an unlabeled boolean arg, of which I'm not a fan). I proposed `{delete: true}` because that would provide consistency with Model, but I'd also be okay with `{remove: true}`.

Eric Ferraiuolo

YUI Developer

Posted: 01/24/12

I too do not like unlabeled boolean args, and using an object makes it easier to add features while maintaining back-compat, so let's stick with that. I just feel strongly that `{delete: true}` shouldn't be used, because it is too easy to forget to actually write: `{'delete': true}`, and not doing so causes an error in IE.

Ryan Grove

YUI Developer

Posted: 01/24/12

Fair enough. I'll go with `{remove: true}`.

Ryan Grove

YUI Developer

Posted: 02/7/12
  • completed changed from 0 to 0.3
  • remaining changed from 0.3 to 0
  • status changed from accepted to checkedin

Implemented in commit da3fe82a.

Jenny Donnelly

YUI Developer

Posted: 05/10/12
  • resolution changed to fixed

checkedin -> closed

Jenny Donnelly

YUI Developer

Posted: 05/10/12
  • status changed from checkedin to closed

checkedin -> closed