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

ember-debounced-properties

v0.0.5

Published

Simple way to define debounced properties

Downloads

79

Readme

Ember Debounced Properties Mixin Build Status

Creates debounced (delayed) versions of properties listed in the debouncedProperties array. For each of these properties, a debounced<property-name> version is created with a default delay of 1000ms. You can override this by defining <property-name>Delay.

Useful when you want to delay a property update, for example when the user types into an input box, and you don't want to initiate a network- or CPU-intensive operation, such as an HTTP request until the user didn't finish typing.

Installation

$ npm install ember-debounced-properties --save-dev

Usage

  1. Extend your Ember.Object (such as an Ember.Component) with the mixin.

    import Ember from 'ember';
    import DebouncedPropertiesMixin from 'ember-debounced-properties/mixin';
         
    export default Ember.Component.extend(DebouncedPropertiesMixin, {
      debouncedProperties: ['value']
    });
  2. Use debouncedValue inside the component's template

    <h2>{{debouncedValue}}</h2>
  3. debouncedValue will follow value after a short delay. You can set the delay with valueDelay.

    {{input value=value}} <- after you done typing it will appear 1.5 seconds later below
    {{my-component value=value valueDelay=1500}}

Gravatar Example

// components/gravatar-image.js

import DebouncedPropertiesMixin from 'ember-debounced-properties/mixin';
var computed = Ember.computed;
var alias = Ember.computed.alias;

export default Ember.Component.extend(DebouncedPropertiesMixin, {
  tagName: 'img',
  attributeBindings: ['src'],

  debouncedProperties: ['email'],
  emailDelay: 2000, // optional, 1000ms by default

  src: alias('gravatarUrl'),
  gravatarUrl: computed('debouncedEmail', function() {
    return '//www.gravatar.com/avatar/'+md5(this.get('email'));
  })
});
{{gravatar-image email='[email protected]'}}

Experimental ES7 decorator syntax

Inspired by @rwjblue's awesome ember-computed-decorators, it is possible to use the ES7 decorator syntax to define debounced properties without using the mixin. All you have to do is just put a decorator over the property you want to have a debounced version. It can be a regular or a computed property, both will work.

import Ember from 'ember';
import debounced from 'ember-debounced-properties/decorator';

export default Ember.Component.extend({
  firstName: 'John',
  lastName: 'Doe',

  @debounced(2000)
  fullName: Ember.computed('firstName', 'lastName', function() {
    return `${firstName} ${lastName}`;
  })
});

The result is the same as with the mixin: both debouncedFullName and fullNameDelay are accessible on the object. For convenience, the delay can be set from the decorator, but the if fullNameDelay exist, it will have precedence, since it could be set at runtime as well. When you call the decorator without arguments (just @decorator), the default 1000ms delay will be used.

Usage

Refer to ember-computed-decorators' Babel Setup chapter.

One More Thing™

It is, of course, could be used together with ember-computed-decorators!

@debounced
@computed('firstName', 'lastName')
fullName(firstName, lastName) {
  return `${firstName} ${lastName}`;
}

Contributing

Installation

  • git clone this repository
  • npm install
  • bower install

Running

  • ember server
  • Visit your app at http://localhost:4200.

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

License

Copyright (c) 2014 Gabor Babicz (MIT License)