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_views

v0.7.5

Published

A collection of views similar to django views

Downloads

4

Readme

Backbone views

Provides some basic views to help you get started using Backbone

All examples below are written in coffeescript. (That's what this library is written in.)

Views

MixinView

Provides an easy interface to mixins. All class based views in this package will use this as their base class.

bv = require("backbone_views")

class MyView extends bv.views.MixinView
  mixins: [bv.mixins.SelectorMixin]

A mixin is just a class. The prototype will be mixed in the current class. If a mixin method is provided by the mixin, the it will be called during the view's initialize method.

This view also provides basic rendering. It will call the template property of the view if it exists.

Default Generic Views

The views below are just simple implementations that use the mixins listed at the bottom of the doc. For complicated stuff, you probably should write your own.

ListView

Uses the ListMixin below and a DetailView to provide a functioning list. This view only requires that you give it a collection and it will make an auto managed list.

CreateView

A simple view that uses the FormMixin to create and add a model to a collection. You must provide a collection for this view to work.

DetailView

Uses the DetailMixin below

UpdateView

A simple view that updates a model using the FormMixin

DeleteView

A simple view that provides a confirm form before destroying a model

Mixins

NunjucksMixin

Gives function to render a nunjucks form.

bv = require("backbone_views")


class MyView extends bv.views.MixinView
  mixins: [bv.mixins.NunjucksMixin]
  template: require("my_view.html")

You can provide a getContext function to extend the context

SelectorMixin

Selects elements after rendering

bv = require("backbone_views")


class MyView extends bv.views.MixinView
  ui:
    input: ".form input#foo"

  # here is how you can use it, it will be jQueryied
  myFunc: () -> alert @ui.input.val()

FormMixin

Provides a renderForm method to render a form from the npm forms package. (Dang, that sentence is not formed well :D )

bv = require "backbone_views"
forms = require "forms"


class MyView extends bv.views.MixinView
  mixins: [bv.mixins.FormMixin]  
  form: forms.create(
    name: form.fields.string(required: true)
  )

BootstrapFormMixin

A form mixin that provides a bootstrapping form render function bootstrapField for those who use bootstrap3

ListMixin

When this mixin is provided a collection it will register listeners to auto populate the collection in the view.

If a listSelector isn't provided or selects nothing, it will assume the list should be populated on the view's el.

If an emptySelector is provided, it will hide/show the selector's results whenever the list is empty/exists

bv = require("backbone_views")
Backbone = require("backbone")


class MyView extends bv.views.MixinView
  mixins: [bv.mixins.ListMixin]  
  listSelector: ".list"
  emptySelector: ".empty"
  collection: new Backbone.Collection([{foo: "boo"}])
  template: '...'

DetailMixin

This provides an easy way to bind properties to a view. Set the property name and a selector on the bindings property and then this model and the dom will be kept in sync

By default it will autobind unbound attrs to "data-{{ name }}", but you can set the autoBind property to change it to something else or turn off this feature.

You can further customize what bound elements will do by setting the "data-{{ name }}" value:

  • toggle: display or hide depending on data value
  • inverse-toggle: like toggle but inverted
  • pluralize: shows element contents if value not 1
  • data: sets a "data-" attribute instead of content
  • href: sets the href instead of content
  • attr: sets an attr instead of content
  • prop: sets a property instead of content (booleans)
  • prop-inverse: like prop but inverted

by default it will replace the contents of the element

bv = require("backbone_views")
Backbone = require("backbone")


class MyView extends bv.views.MixinView
  mixins: [bv.mixins.DetailView]  
  bindings:
    fruit: "div .apple"
  template: '...'