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

Make a public detachView #3155

Merged
merged 6 commits into from
Sep 7, 2016
Merged

Conversation

paulfalgout
Copy link
Member

@paulfalgout paulfalgout commented Aug 31, 2016

This function removes the need for a preventDestroy option. #2640

Essentially if you want to preventDestroy just detach the view first. When you want to preventDestroy you already have to have a copy of the view.. and depending on what is doing the view emptying preventDestroy can become a round about API.

What you really want is

const myView = myRegion.currentView;
myRegion.detachView();
myOtherRegion.show(myView);

Upon approval:

  • Tests
  • Docs

This function removes the need for a `preventDestroy` option.

Essentially if you want to `preventDestroy` just detach the view first. When you want to preventDestroy you already have to have a copy of the view.. and depending on what is doing the view emptying `preventDestroy` can become a round about API.

What you really want is
```js
const myView = myRegion.currentView;
myRegion.detachView();
myOtherRegion.show(myView);
```
@paulfalgout paulfalgout added this to the v3.x milestone Aug 31, 2016
@rafde
Copy link
Member

rafde commented Aug 31, 2016

how about

var view = parentView.detachChildView('region');
myOtherRegion.show(myView);

which proxies detachView. That way people don't directly interact with the region.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.604% when pulling ba4c9d7 on paulfalgout:region-detachview into 8d41fc5 on marionettejs:next.

@paulfalgout
Copy link
Member Author

I think a detachChildView makes since, but I'd think it'd be added along side.. similarly to showChildView where that's the suggested API, but you can interact with the Region if need be. And I think #3156 is a reason you may want to..

@JSteunou
Copy link
Contributor

JSteunou commented Sep 1, 2016

Hooo I like those ideas. @rafde your idea of an API from layout point of view is cool!

@rafde
Copy link
Member

rafde commented Sep 1, 2016

Yeah, I'm 👍 for this. Someone in gitter wanted something like this. @paulfalgout mind if I help with the View#detachChildView part? Or just general help? Or you got this?

@rafde
Copy link
Member

rafde commented Sep 1, 2016

detachChildView(region){
  return this.getRegion(region).detachView();
}
detachView() {
  const view = this.currentView;
  if(!view){
    return;
  }
  delete this.currentView;
  this._detachView(view);
  delete view._parent;
  return view; // I think this should return the view getting detached
},

@paulfalgout
Copy link
Member Author

@rafde you can take it over if you want.

good call about the return if !view
And you're totally right about returning the view.. I almost did that at first, but every other function was returning this.. however add/remove functions elsewhere return the view.

@rafde
Copy link
Member

rafde commented Sep 1, 2016

Ah right, @paulfalgout. I get that you don't want to write up the test, 😄 .
Can this work be placed in the marionettejs repo branch? Or should I just PR against your fork branch?

@paulfalgout
Copy link
Member Author

@rafde we can move it, or you can PR on my branch, or just close this and reopen another.. I'm up for whatever.. I mean I'll also do it eventually, but if you wanted to step in 👯

@rafde
Copy link
Member

rafde commented Sep 2, 2016

I'll PR against yours for now.
I'm thinking we should start creating repo branches for collab work.

detachView
* falsy check

Regions
detachChildView
detachChildView
detachView
@rafde
Copy link
Member

rafde commented Sep 4, 2016

@paulfalgout paulfalgout#4 forgot the docs, though.

rafde and others added 2 commits September 4, 2016 16:15
[documentation] View#detachChildView
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 3f4e701 on paulfalgout:region-detachview into 8d41fc5 on marionettejs:next.

@ahumphreys87
Copy link
Member

Nice i like this. Should we add a deprectation notice to preventDestroy?

@@ -180,6 +180,10 @@ export default {
return region.show(view, ...args);
},

detachChildView(name) {
return this.getRegion(name).detachView();
Copy link
Member

Choose a reason for hiding this comment

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

forgot to do a region exist check

  const region = this.getRegion(name);
  if (!region) {
    return;
  }
  return region.detachView(); 

Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW that check isn't being done in other places

@rafde
Copy link
Member

rafde commented Sep 6, 2016

welp, I am done here. 👍

@JSteunou
Copy link
Contributor

JSteunou commented Sep 6, 2016

Nice! Just concerned about that check on getRegion(''). I understand adding the check is not a thing in Marionette src code and it would silent catch an error making difficult to debug, but could checking + logging in debug mode be a nice feature?

@rafde
Copy link
Member

rafde commented Sep 7, 2016

@JSteunou I am not sure what you are looking for. Snippet of what you mean by "checking + logging in debug mode", please.

@paulfalgout
Copy link
Member Author

I'm in general more interested in consistency over completeness. Even if it is decided that we should be throwing a warning in debug or an error or whatever.. we should handle that in a later issue and across the lib.

@rafde
Copy link
Member

rafde commented Sep 7, 2016

I am for that sentiment.

@paulfalgout
Copy link
Member Author

@ahumphreys87 #3168

@paulfalgout paulfalgout modified the milestones: v3.1, v3.x Sep 7, 2016
@JSteunou
Copy link
Contributor

JSteunou commented Sep 7, 2016

@paulfalgout completely agreed, just throwing the ball. Wouldnt make this PR fuzzy with a lot of changes not related.

Nice work btw guys 👍

@scott-w
Copy link
Member

scott-w commented Sep 7, 2016

I'll add a 👍 too

@scott-w scott-w merged commit 8c36b65 into marionettejs:next Sep 7, 2016
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.

6 participants