Socket
Book a DemoInstallSign in
Socket

backbone.lazify

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone.lazify

Call any method lazily

0.0.8
latest
Source
npmnpm
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Backbone.Lazify

Circle CI

Why do today what you can do tomorrow?

Sometimes you want to wait for things to calm down before invoking a function. Maybe you want to persist a value after a user has finished dragging around a color picker or some other rapid event. You don't want to keep hammering the server so you reach for underscores' debounce method.

This module allows you to called debounced methods on your Backbone models (or other things if you wish) with a bit less boilerplate.

Installation

$ npm install backbone.lazify

There's a bower package too but you'll want to work out how to build the es6 modules yourself.

Usage

You will need to mix the module into Backbone.Model to use across all models, or you can mixin to individual models if you so wish.

import _ from "underscore";
import Backbone from "backbone";
import Lazify from "backbone.lazify";

_.extend(Backbone.Model.prototype, Lazify);

const LazyModel = Backbone.Model.extend({
  foo(day) {
    console.log(`why do today what you can do ${day}`);
  }
});

let exampleModel = new LazyModel();

exampleModel.foo("now"); // instantly prints 'why do today what you can do now'

exampleModel.lazy("foo", "tomorrow"); // prints 'why do today what you can do tomorrow' after 500ms of inactivity

You can override the default debounce time (500ms) on per method basis:

const LazyModel = Backbone.Model.extend({
  lazify: {
    foo: 10000
  },
  foo(day) {
    console.log(`why do today what you can do ${day}`);
  }
});

let exampleModel = new LazyModel();

exampleModel.foo("now"); // instantly prints 'why do today what you can do now'

exampleModel.lazy("foo", "tomorrow"); // prints 'why do today what you can do tomorrow' after 1000ms of inactivity

FAQs

Package last updated on 17 Sep 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.