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

Expose normalizeUIString #3178

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/marionette.region.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ managing regions throughout your application.
* [Showing a View](#showing-a-view)
* [Hiding a View](#hiding-a-view)
* [Preserving Existing Views](#preserving-existing-views)
* [Detaching Existing Views](#detaching-existing-views)
* [Checking whether a region is showing a view](#checking-whether-a-region-is-showing-a-view)
* [`reset` A Region](#reset-a-region)

Expand Down Expand Up @@ -219,6 +220,23 @@ mainRegion.empty({preventDestroy: true});
**NOTE** When using `preventDestroy: true` you must be careful to cleanup your
old views manually to prevent memory leaks.

### Detaching Existing Views
If you want to detach an existing view from a region, use `detachView`.

```javascript
var myView = new MyView();

var myOtherView = new MyView();

var childView = new MyChildView();

// render and display the view
myView.showChildView('main', childView);

// ... somewhere down the line
myOtherView.showChildView('main', myView.getRegion('main').detachView());
```

### Checking whether a region is showing a view

If you wish to check whether a region has a view, you can use the `hasView`
Expand Down
29 changes: 29 additions & 0 deletions docs/marionette.view.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ multiple views through the `regions` attribute.
* [Managing Sub-views](#managing-sub-views)
* [Showing a view](#showing-a-view)
* [Accessing a child view](#accessing-a-child-view)
* [Detaching a child view](#detaching-a-child-view)
* [Organizing your View](#organizing-your-view)
* [Events](#events)
* [onEvent Listeners](#onevent-listeners)
Expand Down Expand Up @@ -198,6 +199,34 @@ var MyView = Mn.View.extend({

If no view is available, `getChildView` returns `null`.

#### Detaching a child view
You can detach a child view from a region through `detachChildView(region)`

```javascript

var Mn = require('backbone.marionette');
var SubView = require('./subview');

var MyView = Mn.View.extend({
template: '#tpl-view-with-regions',

regions: {
firstRegion: '#first-region',
secondRegion: '#second-region'
},

onRender: function() {
this.showChildView('firstRegion', new SubView());
},

onMoveView: function() {
var view = this.detachChildView('firstRegion');
this.showChildView('secondRegion', view);
}
});
```
This is a proxy for [region.detachView()](./marionette.region.md#detaching-existing-views)

### Region availability
Any defined regions within a `View` will be available to the `View` or any
calling code immediately after instantiating the `View`. This allows a View to
Expand Down
4 changes: 2 additions & 2 deletions src/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ const Behavior = MarionetteObject.extend({
const behaviorEvents = this.normalizeUIKeys(_.result(this, 'events'));

// binds the handler to the behavior and builds a unique eventName
return _.reduce(behaviorEvents, function(events, behaviorHandler, key) {
return _.reduce(behaviorEvents, (events, behaviorHandler, key) => {
if (!_.isFunction(behaviorHandler)) {
behaviorHandler = this[behaviorHandler];
}
if (!behaviorHandler) { return; }
key = getUniqueEventName(key);
events[key] = _.bind(behaviorHandler, this);
return events;
} , {}, this);
}, {});
},

// Internal method to build all trigger handlers for a given behavior
Expand Down
Loading