Marionette.Native
A drop-in replacement for Marionette views (View, CollectionView, NextCollectionView) that uses only native DOM methods for element selection and event delegation. It has no dependency on jQuery.
Usage
When using a script tag, the view classes and the mixin can be found at Marionette.Native namespace Example:
var NativeView = MarionetteNativeNativeView;var mixin = MarionetteNativemixin;
Builtin view classes
;var MyView = NativeView; var MyCollectionView = NativeCollectionView; var MyNextCollectionView = NativeNextCollectionView;
mixin
As an alternative, you may extend an existing View's prototype to use native methods, or even replace Backbone.View itself:
;;var MyBaseView = View;
or
;;var MyBaseView = View;_;
or
// patch Marionette view classes directly;;_;
Remove jQuery dependency
To remove jQuery dependency put the following code in start of application
1) Patch the Marionette classes
;;_;_;_;Region;
or
Backbone.ajax
2) Patch With Backbone.NativeAjax
or with Backbone.Fetch
or with Dom7 (Framework7)
Backboneajax = Dom7ajax
3. Fake jquery
With webpack
//nojquery.js - in same dir as webpack.config.js
module.exports = function() {};
//webpack.config.jsmoduleexports = // [..] resolve: alias: jquery: path ;
or with script tag:
Features
Delegation:
var view = el: '#my-element';view;
Undelegation with event names or listeners,
view;view;
View-scoped element finding:
// for one matched element_; // for multiple matched elements_;var fields = _;
Requirements
Marionette.Native makes use of querySelector
and querySelectorAll
. No support for IE8.
Notes
- The
$el
property is set to an array containingview.el
. View#$
returns a NodeList instead of a jQuery context. You can iterate over either using_.each
.- The event object, passed in event handlers, is the native one which,
among other things, handles
currentTarget
differently. On the other hand, the non standarddelegateTarget
is properly set in the event object.
With many thanks to @wyuenho and @akre54 for their initial code.