marionette-v3-compat v0.1.1
marionette-v3-compat
Transitional monkey patch to make Marionette v3 compatible with v2.
Do NOT use this library in production! This library is meant as a transitional tool only. It is not guaranteed to be 100% backwards compatible and it will certainly be less performant.
Currently using v3.0.0-pre.5.
Include and execute this library directly after marionette prior to using the library.
You can turn off certain patches by passing an object setting patches to false.
// main.js
import _ from 'underscore';
import Backbone from 'backbone';
import Marionette from 'backbone.marionette'
import Patch from 'marionette-v3-compat';
// turn off the ItemView and LayoutView patch
Patch({
ItemView: false,
LayoutView: false
});Current backport or shimming
If you are currently backporting v3 functionality or shimming in Radio for Wreqr you may need to remove these modifications.
Available Patches
- ApplicationWreqr: Global channel on Application -
app.ventapp.reqresandapp.commandswere removed from Application as well as theapp.requestandapp.executeshortcuts. - bindEntityEvents: All uses of
bindEntityEventswere renamedbindEventsandunbindEntityEventswere renamedunbindEvents. Additionally these functions no longer acceptbindingsas a function. You must pass an object. - childEvents:
childEventswas renamedchildViewEvents - CollectionView:
CollectionViewhad a number of methods privatized - Controller:
Controllerwas removed in v3 - deprecatedEvents: throws deprecation notices for a number of removed events
render:collectionwas renamedrender:childrendestroy:collectionwas renameddestroy:childrenrender:templateis no longer triggered.
- getChildView:
getChildViewwas removed from CollectionView aschildViewcan now accept a function. AlsogetEmptyViewwas removed from CollectionView asemptyViewcan now accept a function. - ItemView:
Marionette.ItemViewis nowMarionette.Viewin v3 - LayoutView:
Marionette.LayoutViewis nowMarionette.Viewin v3 - Module:
Modulewas removed in v3 - normalizeUi:
normalizeUIString,normalizeUIKeysandnormalizeUIValueswere removed. - proxyFunctions:
proxyGetOption,proxyBindEntityEventsandproxyUnbindEntityEventswere removed. Use - Region: Region swap events and
attachViewwere removed. By defaultshowwill not re-render a rendered view, soattachViewis unnecessary. - RegionManager:
RegionManagerwas removed in v3. TheMarionette.actAsCollectionutility was only used byRegionManager, so it was also removed. - RegionShowEvent: Showing a view in a region no longer triggers a show event on the View in v3
- regionsOnApplication: Region instances are no longer appended to the Application. Application has only one region and to access it use
getRegion. - regionsOnView: Region instances are no longer appended to the View. Use
getRegionto get the region by name from the view.- One caveat is this patch creates a new instance of the region. If you
listenToa region attached to the view it will not receive the events of the region fromgetRegion. The patch assumes some consistency.
- One caveat is this patch creates a new instance of the region. If you
- RegionStaticMethods: The static build methods for a Region were removed in v3.
- templateHelpers: View's
templateHelpersis nowtemplateContextin v3 - triggerProxy: View events proxied to a parent layout no longer automatically prepend the view as the 1st argument.
Known Issues
Marionette v3 no longer uses Wreqr. This library shims Radio over the Wreqr API. If you are using Wreqr directly sharing channels they will not communicate with the Application's channel.
Changes to
Marionette.deprecateare not accounted for.
Unaccounted for breaking changes:
In v2 many options passed on instantiation could be modified after instantiation. In v3, options are merged on instantiation and not used internally afterwards. To modify the option passed in on v3, modify the value on the instance itself.
Region: before:show / show events in v2 passed the view, the region, and options, but in v3 pass the region, the view and options
- Region: before:empty / empty events in v3 now pass the region as the first argument
- Region: before:destroy / destroy events in v3 now pass the region as the first argument
Region: show({forceShow: true}) was removed. In v3 a view is rendered if it was not previously and it is show if it was not shown previously. If you need to retrigger events, either re-render or empty/show again.
Application: In v2 options passed while instantiating an Application were merged onto the Application. This was removed in v3 and not re-implemented here.
Object destroy events now pass the view as the 1st argument.
CollectionView.isEmpty is no longer passed the
collectionas the first argument.- CollectionView
onAddChildandonRemoveChildare now passed the collectionView as the 1st argument and the childView as the second. CollectionView.renderChildView was removed entirely
View.delegateEvents / View.undelegateEvents no longer delegate entity events. Those are delegated separately in v3.
- View.isRendered / View.isDestroyed flags in v2 are now functions in v3. This is not accounted for here.
- View.triggers in v2 passed a object to the handler containing the view, model, and collection. In v3 instead of this option, simply the view is passed (which will contain the model or collection anyhow).
- View.serializeModel in v3 uses
this.modeland does not takemodelas an argument. - View.destroy in v3 doesn't call
Backbone.View.removedirectly however all pieces of it are called. As long as someone isn't overriding remove in Backbone, this is a non-breaking change. - View destroy events now pass the view as the 1st argument.
- View.modelEvents and View.collectionEvents were bound on
delegateEventsin v2, but it was separated in v3 into its owndelegateEntityEvents. Entity events are now only bound upon initialization. - View
add:regionandremove:regionnow pass the view as the 1st argument - View does not have an attached
RegionManager. - View
childViewEvents(previously namedchildEvents) are calculated and cached when theeventshas is delegated instead of on eachtrigger. - View - the v2 Layout's destroyImmediate is the default functionality of View's in v3.
- LayoutView.regions were passed the
optionsfrom the view's instantiation due to thegetOptionnot being available. This is no longer the case in v3 andgetOption(orthis.options) will work to get options.