npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone.waiter

v2.0.1

Published

tiny library to add backbone structure and a marionette feel to your server side views

Downloads

8

Readme

backbone.waiter

tiny library (1KB gziped) to add backbone structure and a marionette feel to your server side views.

Purpose

I really like the structure backbone and marionette give the JS code for your views. This library is to help give that structure to views that are rendered server side. via .NET, PHP, or whatever server language you are using.

Inspiration

Most of the base code was borrowed from backbone.marionette v2.4. The only reason this exist and not just use all of Marionette is for a special use case. Where I wanted the JS code to be as small as possible and I didn't need all the other goodness Mn provides.

So I just cherry picked the smallest amount of code I could to get what I wanted. A single base view with the ui hash.

Unlike Marionette there is no automatic event binding to backbone models or support for child views or templates. This is b/c this library is only meant to be used when dealing only and directly with server side views. If you need more of what Marionette provides you should use the real thing.

Dependencies

  1. jQuery
  2. underscore / lodash
  3. backbone

Dist Files

There are two main packages

  • backbone.waiter.js
    • The default package
    • Only the core code
  • backbone.waiter.bundle.js
    • Bundled version
      • includeds Backbone and Underscore
    • Does not include jQuery
      • this is to let you pick your own version of jQuery should work with any version Backbone will work with.

Usage

BaseView

var MyView = Backbone.Waiter.BaseView.extend({
	el: '.mainView', // where the view starts 

	initialize: function(){
		// called when view is instantiated
		// the ui hash and events are not ready yet
	},	
	
	// jQuery selectors stored in a hash
	ui: {
		// prop: selector
		btnSubmit: '#btnSubmit'
	},	
		
	events:{
		// event selector/@ui.prop: function
		'click @ui.btnSubmit': 'onbtnSubmit'
	},

	onbtnSubmit: function(e){
		e.preventDefault();
		alert('I got clicked');
	},

	onRender: function(){
		// the Dom is ready you can now use the ui hash
	}
});

Render the view

To get the view to hook up events and initialize render() needs to be called.

This can be done anywhere you want on the page itself or as part of the view code.

$(function(){
	if($('.mainView').length > 0) {
		// initialize the view
		var _myView = new MyView(); 

		// hook up ui and events
		_myView.render();
	}
});

AutoLoader

To assist in bundling code the autoloader can also be used to test what views should be loaded when the page renders.

It simply checks your el against the dom and if its found initializes the view and renders it.

// import/require  the views
var FooView = require('./views/FooView')
var BarView = require('./views/BarView ')

// create view array to store them
var viewArray = [
  FooView,
  BarView
]

// loop throuch each view 
$(function () {
  for (var i = 0; i < viewArray.length; i++) {
    Waiter.AutoLoader(viewArray[i])
  }
})

Changelog

Updates and changes between versions will be kept here.

License

MIT