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 🙏

© 2025 – Pkg Stats / Ryan Hefner

wwl-js-backbone-extensions

v0.2.5

Published

| Current Version | Master | Develop | |-----------------|--------|---------| | [![npm version](https://badge.fury.io/js/wwl-js-backbone-extensions.svg)](https://badge.fury.io/js/wwl-js-backbone-extensions) | [![Build Status](https://travis-ci.org/wonderw

Readme

wwl-js-backbone-extensions

| Current Version | Master | Develop | |-----------------|--------|---------| | npm version | Build Status | Build Status |


Abstract model

Usage

class Article extends require('wwl-js-backbone-extensions').AbstractModel

  rootName: 'article'     # default: 'data'

  # You can combine them:
  jsonOmitted: ['comments']                 # default: []
  jsonPermitted: ['id', 'title', 'rating']  # default: []

  syncWithoutRoot: false  # default: false

  binaryId: true          # default: false

  # You need to implement this
  getRandomBinaryId: ->
    @getOption('context').getSecureRandom().secureHexRandom(128)

  # You need to implement this
  prependedUrlRoot: (url = '') ->
    @context.getUrlHelpers().prependUrlHost(url)
context = your.context.here
model   = new Article({}, { context: context })

Events


model.on 'before:save', (model, key, val, options) -> #...
model.on 'beforeSync', (method, model, options) -> #...
model.on 'remoteErrors:[...backbone collection events...]', #...
model.on 'localErrors:[...backbone collection events...]', #...
model.on 'errors:[...backbone collection events for both collections combined...]', #...
model.on 'dirty:change', (model, dirty) -> # ...

Dirty

Dirty requires the server to send updated_at as part of the response. If updated_at changes, the model will be unmarked as dirty.


model.isDirty() # e.g. false
model.set('name', 'test')
model.isDirty() # e.g. true
model.save()
model.isDirty() # e.g. false

model.isDirty() # e.g. false
model.setDirty()
model.isDirty() # e.g. true
model.setDirty(false)
model.isDirty() # e.g. false

Persistance


# If it's synced at least once
model.isSynced()

# If it's currently syncing
model.isSyncing()

# If it's a new model
model.isNew()

# Save the model
model.save()

Validations


# An errors collection for local errors (you need to maintain it by yourself)
model.getLocalErrors()

# An errors collection build by the errors-attribute from the server response.
model.getRemoteErrors()

# An array of the errors concatenated from `getLocalErrors()` and `getRemoteErrors()`
model.getErrors()

# If there are local and/or remote errors.
# It calls (backbone feature) the validate function if defined. So you could run your
# local validations there (http://backbonejs.org/#Model-isValid).
model.isValid()

# If there are local errors
model.isLocalValid()

# If there are remote errors
model.isRemoteValid()

# You can run the is...Valid function with one attribute key too, to check just that one.
model.isValid('title')
model.isLocalValid('title')
model.isRemoteValid('title')

Helpers


# Returns the models sync root name - "data" by default
model.getRootName()

# Returns the meta data sent by the server
model.getMeta()

# Unset all attributes except of the id.
# You can pass { discardId: true } to unset id too.
model.unsetAll()

Abstract collection


class ArticlesCollection extends require('wwl-js-backbone-extensions').AbstractCollection

  rootName: 'article'     # default: 'data'

  syncWithoutRoot: false  # default: false

  model: Article

  url: '/articles'

  # You need to implement this
  prependedUrl: (url = '') ->
    @context.getUrlHelpers().prependUrlHost(url)
context     = your.context.here
collection  = new ArticlesCollection([], { context: context })

Persistance


# If it's synced at least once
collection.isSynced()

# If it's currently syncing
collection.isSyncing()

Helpers


# If there is already the model for the passed id inside the collection, it will return it
# without fetching it - except you're passing true for fetch.
# Attributes will be set to the model
result = collection.getOrFetch(id, attributes = {}, fetch = false)
result.model # the model instance
result.jqxhr # *optional* - the jqxhr request if available

# Returns the model instance (builds it if necessary)
model = collection.getOrInitialize(id, attributes = {}, options = {})

# Returns the models sync root name - "data" by default
collection.getRootName()

# Returns the meta data sent by the server
collection.getMeta()