-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2871 from paulfalgout/refactor/reorg-mixins
Various v3 mixin cleanup
- Loading branch information
Showing
8 changed files
with
106 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
bindEntityEvents, | ||
unbindEntityEvents | ||
} from '../bind-entity-events'; | ||
|
||
export default { | ||
// Handle `modelEvents`, and `collectionEvents` configuration | ||
_delegateEntityEvents: function(model, collection) { | ||
this._undelegateEntityEvents(model, collection); | ||
|
||
var modelEvents = this.getValue(this.getOption('modelEvents')); | ||
bindEntityEvents.call(this, model, modelEvents); | ||
|
||
var collectionEvents = this.getValue(this.getOption('collectionEvents')); | ||
bindEntityEvents.call(this, collection, collectionEvents); | ||
}, | ||
|
||
_undelegateEntityEvents: function(model, collection) { | ||
var modelEvents = this.getValue(this.getOption('modelEvents')); | ||
unbindEntityEvents.call(this, model, modelEvents); | ||
|
||
var collectionEvents = this.getValue(this.getOption('collectionEvents')); | ||
unbindEntityEvents.call(this, collection, collectionEvents); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import _ from 'underscore'; | ||
import getUniqueEventName from '../utils/getUniqueEventName'; | ||
|
||
// Internal method to create an event handler for a given `triggerDef` like | ||
// 'click:foo' | ||
function buildViewTrigger(view, triggerDef) { | ||
if (_.isString(triggerDef)) { | ||
triggerDef = {event: triggerDef}; | ||
} | ||
|
||
const eventName = triggerDef.event; | ||
const shouldPreventDefault = triggerDef.preventDefault !== false; | ||
const shouldStopPropagation = triggerDef.stopPropagation !== false; | ||
|
||
return function(e) { | ||
if (shouldPreventDefault) { | ||
e.preventDefault(); | ||
} | ||
|
||
if (shouldStopPropagation) { | ||
e.stopPropagation(); | ||
} | ||
|
||
view.triggerMethod(eventName, view); | ||
}; | ||
} | ||
|
||
export default { | ||
|
||
// Configure `triggers` to forward DOM events to view | ||
// events. `triggers: {"click .foo": "do:foo"}` | ||
_getViewTriggers: function(view, triggers) { | ||
// Configure the triggers, prevent default | ||
// action and stop propagation of DOM events | ||
return _.reduce(triggers, function(events, value, key) { | ||
key = getUniqueEventName(key); | ||
events[key] = buildViewTrigger(view, value); | ||
return events; | ||
}, {}, this); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters