Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
backbone-subviews
Advanced tools
A minimalist view mixin for creating and managing subviews in your Backbone.js applications.
A minimalist view mixin for creating and managing subviews in your Backbone.js applications.
This plugin is designed to manage a fixed number of subviews. See Backbone.CollectionView for a plugin to manage a dynamic number of subviews (i.e. an array of subviews).
<div data-subview="mySubview"></div>
this.subviews.mySubview
BONUS: Use Backbone.Subviews in conjunction with Backbone.Courier and Cartero / Parcelify for a completely modularized backbone.js experience.
In a view template, insert a subview "mySubview" using a placeholder div
with a data-subview
attribute:
<script type='text/template' id="MyItemViewTemplate">
<h1>This is my item view template</h1>
<div data-subview="mySubview"></div>
</script>
Now in MyItemView.js:
MyItemViewClass = Backbone.View.extend( {
initialize : function() {
// Add backbone.subview functionality to this view.
Backbone.Subviews.add( this );
},
subviewCreators : {
"mySubview" : function() {
var options = {};
// Do any logic required to create initialization options,
// then instantiate and return the new subview object.
return new MySubviewClass( options );
}
},
render : function( data ) {
// `render` funciton is just like normal.. nothing new here.
var templateFunction = _.template( $( "#MyItemViewTemplate" ).html() );
this.$el.html( templateFunction( data ) );
// After we are done rendering, our subviews will automatically be rendered in order
},
onSubviewsRendered : function() {
// This method (if it exists) is called after subviews are finished rendering.
// Anytime after subviews are rendered, you can find the subviews in the `subviews` hash
this.listenTo( this.subviews.mySubview, "highlighted", this._mySubview_onHighlighted );
},
...
} );
To insert a subview, just put <div data-subview="[subviewName]"></div>
in the appropriate place in the parent view's template. This placeholder div
will be completely replaced with the subview's DOM element.
Then include an entry for the subview in the subviewCreators
hash. The key of each entry in this hash is a subview's name, and the value is a function that should create and return the new subview.
After the parent view's render
function is finished, the subviews will automatically be created and rendered (in the order their placeholder div
s appear inside the parent view). Once all subviews have been created and rendered, the parent view's onSubviewsRendered
method is called (if one exists).
When a parent view is re-rendered, its subviews will be re-rendered (i.e. their render
function will be called). By default the original subview objects will by reused in order to preserve subview state. To force the subview objects to be recreated instead of reused, call parentView.removeSubviews()
before re-rendering the parent.
A parent view will automatically remove all its subviews when its remove
method is called.
To further simplify the syntax for inserting subviews in your templates, add a global template helper to your template language of choice. For example, with underscore.js templates, the underscore-template-helpers mixin can be used to support this syntax:
<script type='text/template' id="MyItemViewTemplate">
<h1>This is my item view template</h1>
<%= subview( "mySubview" ) %>
</script>
div
restriction on subview placeholder - placeholders can now be of any type of element._onSubviewsRendered
to onSubviewsRendered
. (Old name depreciated but still works for now.)view.removeSubviews()
method.FAQs
A minimalist view mixin for creating and managing subviews in your Backbone.js applications.
The npm package backbone-subviews receives a total of 28 weekly downloads. As such, backbone-subviews popularity was classified as not popular.
We found that backbone-subviews demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.