Skip to content

Commit

Permalink
v5 Migration
Browse files Browse the repository at this point in the history
DO NOT MERGE

This PR serves as a migration guide for moving to https://github.com/marionettejs/marionette with the exception of Radio integration.

But it should make relevent breaking changes more obvious
  • Loading branch information
paulfalgout committed Nov 12, 2020
1 parent bf8a5ab commit ae073ed
Show file tree
Hide file tree
Showing 22 changed files with 12,021 additions and 971 deletions.
1,216 changes: 876 additions & 340 deletions lib/backbone.marionette.esm.js

Large diffs are not rendered by default.

1,282 changes: 909 additions & 373 deletions lib/backbone.marionette.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/backbone.marionette.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/backbone.marionette.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/backbone.marionette.min.js.map

Large diffs are not rendered by default.

9,508 changes: 9,508 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
},
"github": "https://github.com/marionettejs/backbone.marionette",
"dependencies": {
"backbone.radio": "^2.0.0"
"backbone.radio": "^2.0.0",
"yarn": "^1.22.10"
},
"peerDependencies": {
"backbone": "^1.3.3",
Expand Down
57 changes: 16 additions & 41 deletions src/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
// Behaviors allow you to blackbox View specific interactions
// into portable logical chunks, keeping your views simple and your code DRY.

import _ from 'underscore';
import { extend as _extend, uniqueId, result } from 'underscore';
import extend from './utils/extend';
import getNamespacedEventName from './utils/get-namespaced-event-name';
import CommonMixin from './mixins/common';
import DelegateEntityEventsMixin from './mixins/delegate-entity-events';
import TriggersMixin from './mixins/triggers';
import UIMixin from './mixins/ui';
import ViewEventsMixin from './mixins/view-events';

const ClassOptions = [
'collectionEvents',
Expand All @@ -29,8 +28,12 @@ const Behavior = function(options, view) {
// to the view.
this.view = view;


this._setOptions(options, ClassOptions);
this.cid = _.uniqueId(this.cidPrefix);
this.cid = uniqueId(this.cidPrefix);

this._initViewEvents();
this.setElement();

// Construct an internal UI hash using the behaviors UI
// hash combined and overridden by the view UI hash.
Expand All @@ -39,7 +42,7 @@ const Behavior = function(options, view) {
// This order will help the reuse and share of a behavior
// between multiple views, while letting a view override
// a selector under an UI key.
this.ui = _.extend({}, _.result(this, 'ui'), _.result(view, 'ui'));
this.ui = _extend({}, result(this, 'ui'), result(view, 'ui'));

// Proxy view triggers
this.listenTo(view, 'all', this.triggerMethod);
Expand All @@ -52,12 +55,9 @@ Behavior.extend = extend;
// Behavior Methods
// --------------

_.extend(Behavior.prototype, CommonMixin, DelegateEntityEventsMixin, TriggersMixin, UIMixin, {
_extend(Behavior.prototype, CommonMixin, DelegateEntityEventsMixin, UIMixin, ViewEventsMixin, {
cidPrefix: 'mnb',

// This is a noop method intended to be overridden
initialize() {},

// proxy behavior $ method to the view
// this is useful for doing jquery DOM lookups
// scoped to behaviors view.
Expand All @@ -67,6 +67,8 @@ _.extend(Behavior.prototype, CommonMixin, DelegateEntityEventsMixin, TriggersMix

// Stops the behavior from listening to events.
destroy() {
this._undelegateViewEvents();

this.stopListening();

this.view._removeBehavior(this);
Expand All @@ -76,10 +78,13 @@ _.extend(Behavior.prototype, CommonMixin, DelegateEntityEventsMixin, TriggersMix
return this;
},

proxyViewProperties() {
this.$el = this.view.$el;
setElement() {
this._undelegateViewEvents();

this.el = this.view.el;

this._delegateViewEvents(this.view);

return this;
},

Expand Down Expand Up @@ -110,36 +115,6 @@ _.extend(Behavior.prototype, CommonMixin, DelegateEntityEventsMixin, TriggersMix
this._undelegateEntityEvents(this.view.model, this.view.collection);

return this;
},

_getEvents() {
if (!this.events) { return; }

// Normalize behavior events hash to allow
// a user to use the @ui. syntax.
const behaviorEvents = this.normalizeUIKeys(_.result(this, 'events'));

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

// Internal method to build all trigger handlers for a given behavior
_getTriggers() {
if (!this.triggers) { return; }

// Normalize behavior triggers hash to allow
// a user to use the @ui. syntax.
const behaviorTriggers = this.normalizeUIKeys(_.result(this, 'triggers'));

return this._getViewTriggers(this.view, behaviorTriggers);
}
});

Expand Down
Loading

0 comments on commit ae073ed

Please sign in to comment.