├── app
├── .gitkeep
└── initializers
│ └── extend-ember-computed.js
├── addon
├── .gitkeep
├── throttled.js
└── debounced.js
├── vendor
└── .gitkeep
├── tests
├── unit
│ ├── .gitkeep
│ ├── throttle-test.js
│ └── debounce-test.js
├── dummy
│ ├── app
│ │ ├── helpers
│ │ │ └── .gitkeep
│ │ ├── models
│ │ │ └── .gitkeep
│ │ ├── routes
│ │ │ └── .gitkeep
│ │ ├── views
│ │ │ └── .gitkeep
│ │ ├── components
│ │ │ └── .gitkeep
│ │ ├── controllers
│ │ │ ├── .gitkeep
│ │ │ └── application.js
│ │ ├── templates
│ │ │ ├── components
│ │ │ │ └── .gitkeep
│ │ │ └── application.hbs
│ │ ├── styles
│ │ │ └── app.css
│ │ ├── router.js
│ │ ├── app.js
│ │ └── index.html
│ ├── public
│ │ ├── robots.txt
│ │ └── crossdomain.xml
│ └── config
│ │ └── environment.js
├── test-helper.js
├── helpers
│ ├── resolver.js
│ ├── custom-helpers.js
│ └── start-app.js
├── .jshintrc
└── index.html
├── .bowerrc
├── index.js
├── config
└── environment.js
├── .npmignore
├── testem.json
├── circle.yml
├── .ember-cli
├── .gitignore
├── .travis.yml
├── bower.json
├── .jshintrc
├── .editorconfig
├── Brocfile.js
├── LICENSE.md
├── package.json
├── Gruntfile.js
└── README.md
/app/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/addon/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/vendor/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/unit/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/helpers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/models/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/routes/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/views/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/components/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/controllers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/templates/components/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/public/robots.txt:
--------------------------------------------------------------------------------
1 | # http://www.robotstxt.org
2 | User-agent: *
3 |
--------------------------------------------------------------------------------
/.bowerrc:
--------------------------------------------------------------------------------
1 | {
2 | "directory": "bower_components",
3 | "analytics": false
4 | }
5 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /* jshint node: true */
2 | 'use strict';
3 |
4 | module.exports = {
5 | name: 'rate-limit-computed'
6 | };
7 |
--------------------------------------------------------------------------------
/config/environment.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function(/* environment, appConfig */) {
4 | return { };
5 | };
6 |
--------------------------------------------------------------------------------
/tests/test-helper.js:
--------------------------------------------------------------------------------
1 | import resolver from './helpers/resolver';
2 | import {
3 | setResolver
4 | } from 'ember-qunit';
5 |
6 | setResolver(resolver);
7 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | bower_components/
2 | tests/
3 | tmp/
4 |
5 | .bowerrc
6 | .editorconfig
7 | .ember-cli
8 | .travis.yml
9 | .npmignore
10 | **/.gitkeep
11 | bower.json
12 | Brocfile.js
13 | testem.json
14 |
--------------------------------------------------------------------------------
/tests/dummy/app/styles/app.css:
--------------------------------------------------------------------------------
1 | html {
2 | font-size: 125%;
3 | }
4 | body {
5 | font-size: .75em;
6 | background: #f0f0f0;
7 | font-family: 'raleway', 'open sans', 'helvetica', 'arial', sans-serif;
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/testem.json:
--------------------------------------------------------------------------------
1 | {
2 | "framework": "qunit",
3 | "test_page": "tests/index.html?hidepassed",
4 | "launch_in_ci": [
5 | "PhantomJS"
6 | ],
7 | "launch_in_dev": [
8 | "PhantomJS",
9 | "Chrome"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/tests/dummy/app/router.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 | import config from './config/environment';
3 |
4 | var Router = Ember.Router.extend({
5 | location: config.locationType
6 | });
7 |
8 | export default Router.map(function() {
9 | });
10 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | pre:
3 | - curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash
4 | node:
5 | version: 0.12
6 |
7 | dependencies:
8 | override:
9 | - npm install -g bower
10 | - npm install
11 | - bower install
12 |
--------------------------------------------------------------------------------
/.ember-cli:
--------------------------------------------------------------------------------
1 | {
2 | /**
3 | Ember CLI sends analytics information by default. The data is completely
4 | anonymous, but there are times when you might want to disable this behavior.
5 |
6 | Setting `disableAnalytics` to true will prevent any data from being sent.
7 | */
8 | "disableAnalytics": false
9 | }
10 |
--------------------------------------------------------------------------------
/tests/helpers/resolver.js:
--------------------------------------------------------------------------------
1 | import Resolver from 'ember/resolver';
2 | import config from '../../config/environment';
3 |
4 | var resolver = Resolver.create();
5 |
6 | resolver.namespace = {
7 | modulePrefix: config.modulePrefix,
8 | podModulePrefix: config.podModulePrefix
9 | };
10 |
11 | export default resolver;
12 |
--------------------------------------------------------------------------------
/tests/helpers/custom-helpers.js:
--------------------------------------------------------------------------------
1 | import Ember from "ember";
2 |
3 | export default (function() {
4 |
5 | Ember.Test.registerHelper('getController', function (app, name) {
6 | Ember.assert('helper must be given a controller name', !!name);
7 | return app.__container__.lookup('controller:' + name);
8 | });
9 |
10 | })();
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 | .idea
3 |
4 | # compiled output
5 | /dist
6 | /tmp
7 |
8 | # dependencies
9 | /node_modules
10 | /bower_components
11 |
12 | # misc
13 | /.sass-cache
14 | /connect.lock
15 | /coverage/*
16 | /libpeerconnection.log
17 | npm-debug.log
18 | testem.log
19 |
--------------------------------------------------------------------------------
/app/initializers/extend-ember-computed.js:
--------------------------------------------------------------------------------
1 | import throttled from "rate-limit-computed/throttled";
2 | import debounced from "rate-limit-computed/debounced";
3 |
4 | export default {
5 | name: 'extend-ember-computed',
6 | initialize: function() {
7 | Ember.computed.throttle = throttled;
8 | Ember.computed.debounce = debounced;
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | language: node_js
3 | node_js:
4 | - "0.12"
5 |
6 | sudo: false
7 |
8 | cache:
9 | directories:
10 | - node_modules
11 |
12 | before_install:
13 | - "npm config set spin false"
14 | - "npm install -g npm@^2"
15 |
16 | install:
17 | - npm install -g bower
18 | - npm install
19 | - bower install
20 |
21 | script:
22 | - npm test
23 |
--------------------------------------------------------------------------------
/tests/dummy/app/app.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 | import Resolver from 'ember/resolver';
3 | import loadInitializers from 'ember/load-initializers';
4 | import config from './config/environment';
5 |
6 | var App;
7 |
8 | Ember.MODEL_FACTORY_INJECTIONS = true;
9 |
10 | App = Ember.Application.extend({
11 | modulePrefix: config.modulePrefix,
12 | podModulePrefix: config.podModulePrefix,
13 | Resolver: Resolver
14 | });
15 |
16 | loadInitializers(App, config.modulePrefix);
17 |
18 | export default App;
19 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rate-limit-computed",
3 | "dependencies": {
4 | "ember": "1.11.1",
5 | "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
6 | "ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
7 | "ember-data": "1.0.0-beta.16.1",
8 | "ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
9 | "ember-qunit": "0.3.1",
10 | "ember-qunit-notifications": "0.0.7",
11 | "ember-resolver": "~0.1.15",
12 | "jquery": "^1.11.1",
13 | "loader.js": "ember-cli/loader.js#3.2.0",
14 | "qunit": "~1.17.1"
15 | }
16 | }
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "predef": [
3 | "document",
4 | "window",
5 | "-Promise"
6 | ],
7 | "browser": true,
8 | "boss": true,
9 | "curly": true,
10 | "debug": false,
11 | "devel": true,
12 | "eqeqeq": true,
13 | "evil": true,
14 | "forin": false,
15 | "immed": false,
16 | "laxbreak": false,
17 | "newcap": true,
18 | "noarg": true,
19 | "noempty": false,
20 | "nonew": false,
21 | "nomen": false,
22 | "onevar": false,
23 | "plusplus": false,
24 | "regexp": false,
25 | "undef": true,
26 | "sub": true,
27 | "strict": false,
28 | "white": false,
29 | "eqnull": true,
30 | "esnext": true,
31 | "unused": true
32 | }
33 |
--------------------------------------------------------------------------------
/tests/helpers/start-app.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 | import Application from '../../app';
3 | import Router from '../../router';
4 | import customHelpers from './custom-helpers';
5 | import config from '../../config/environment';
6 |
7 | export default function startApp(attrs) {
8 | var application;
9 |
10 | var attributes = Ember.merge({}, config.APP);
11 | attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
12 |
13 | Ember.run(function() {
14 | application = Application.create(attributes);
15 | application.setupForTesting();
16 | application.injectTestHelpers();
17 | });
18 |
19 | return application;
20 | }
21 |
--------------------------------------------------------------------------------
/tests/dummy/public/crossdomain.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 | end_of_line = lf
10 | charset = utf-8
11 | trim_trailing_whitespace = true
12 | insert_final_newline = true
13 | indent_style = space
14 | indent_size = 2
15 |
16 | [*.js]
17 | indent_style = space
18 | indent_size = 2
19 |
20 | [*.hbs]
21 | insert_final_newline = false
22 | indent_style = space
23 | indent_size = 2
24 |
25 | [*.css]
26 | indent_style = space
27 | indent_size = 2
28 |
29 | [*.html]
30 | indent_style = space
31 | indent_size = 2
32 |
33 | [*.{diff,md}]
34 | trim_trailing_whitespace = false
35 |
--------------------------------------------------------------------------------
/Brocfile.js:
--------------------------------------------------------------------------------
1 | /* jshint node: true */
2 | /* global require, module */
3 |
4 | var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
5 |
6 | var app = new EmberAddon({
7 | snippetPaths: ['tests/dummy/snippets'],
8 | snippetSearchPaths: ['app', 'tests/dummy/app', 'addon']
9 | });
10 |
11 | // Use `app.import` to add additional libraries to the generated
12 | // output files.
13 | //
14 | // If you need to use different assets in different
15 | // environments, specify an object as the first parameter. That
16 | // object's keys should be the environment name and the values
17 | // should be the asset to use in that environment.
18 | //
19 | // If the library that you are including contains AMD or ES6
20 | // modules that you would like to import into your application
21 | // please specify an object with the list of modules as keys
22 | // along with the exports of each module as its value.
23 |
24 | module.exports = app.toTree();
25 |
--------------------------------------------------------------------------------
/tests/dummy/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Dummy
7 |
8 |
9 |
10 | {{content-for 'head'}}
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | {{content-for 'head-footer'}}
19 |
20 |
21 | {{content-for 'body'}}
22 |
23 |
24 |
25 |
26 | {{content-for 'body-footer'}}
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/tests/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "predef": [
3 | "document",
4 | "window",
5 | "location",
6 | "setTimeout",
7 | "$",
8 | "-Promise",
9 | "define",
10 | "console",
11 | "visit",
12 | "exists",
13 | "fillIn",
14 | "click",
15 | "keyEvent",
16 | "triggerEvent",
17 | "find",
18 | "findWithAssert",
19 | "wait",
20 | "DS",
21 | "andThen",
22 | "currentURL",
23 | "currentPath",
24 | "currentRouteName",
25 | "getController"
26 | ],
27 | "node": false,
28 | "browser": false,
29 | "boss": true,
30 | "curly": false,
31 | "debug": false,
32 | "devel": false,
33 | "eqeqeq": true,
34 | "evil": true,
35 | "forin": false,
36 | "immed": false,
37 | "laxbreak": false,
38 | "newcap": true,
39 | "noarg": true,
40 | "noempty": false,
41 | "nonew": false,
42 | "nomen": false,
43 | "onevar": false,
44 | "plusplus": false,
45 | "regexp": false,
46 | "undef": true,
47 | "sub": true,
48 | "strict": false,
49 | "white": false,
50 | "eqnull": true,
51 | "esnext": true
52 | }
53 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Dummy Tests
7 |
8 |
9 |
10 | {{content-for 'head'}}
11 | {{content-for 'test-head'}}
12 |
13 |
14 |
15 |
16 |
17 | {{content-for 'head-footer'}}
18 | {{content-for 'test-head-footer'}}
19 |
20 |
21 |
22 | {{content-for 'body'}}
23 | {{content-for 'test-body'}}
24 |
25 |
26 |
27 |
28 |
29 |
30 | {{content-for 'body-footer'}}
31 | {{content-for 'test-body-footer'}}
32 |
33 |
34 |
--------------------------------------------------------------------------------
/tests/dummy/app/controllers/application.js:
--------------------------------------------------------------------------------
1 | // BEGIN-SNIPPET debounce-throttle-example
2 | import Ember from "ember";
3 |
4 | const {
5 | computed,
6 | run
7 | } = Ember;
8 |
9 | export default Ember.Controller.extend({
10 |
11 | cubedTriggered: 0,
12 |
13 | cubed: computed.throttle('count', function() {
14 | var count = this.get('count');
15 | this.incrementProperty('cubedTriggered');
16 | return count * count * count;
17 | }, 16),
18 |
19 |
20 | squaredTriggered: 0,
21 |
22 | squared: computed.debounce('count', function() {
23 | var count = this.get('count');
24 | this.incrementProperty('squaredTriggered');
25 | return count * count;
26 | }, 16),
27 |
28 | count: 0,
29 |
30 | actions: {
31 | plusOne: function() {
32 | this.incrementProperty('count');
33 | },
34 | triggerThree: function() {
35 | this.incrementProperty('count');
36 | run.later(this, function() { this.incrementProperty('count'); }, 4);
37 | run.later(this, function() { this.incrementProperty('count'); }, 4);
38 | }
39 | }
40 |
41 | });
42 | // END-SNIPPET
43 |
--------------------------------------------------------------------------------
/addon/throttled.js:
--------------------------------------------------------------------------------
1 | import Ember from "ember";
2 |
3 | const {
4 | run,
5 | computed
6 | } = Ember;
7 |
8 | const {
9 | throttle,
10 | next,
11 | cancel
12 | } = run;
13 |
14 | export default function throttledProperty() {
15 |
16 | var args = [].slice.apply(arguments);
17 | var rate = args.pop();
18 | var method = args.pop();
19 |
20 | var __value = null;
21 | var __next = null;
22 | var __onDestroy = false;
23 |
24 | var methodFn = function(key, value, oldValue) {
25 | if (!this.get('isDestroyed')) {
26 | __value = method.call(this, key, value, oldValue);
27 | if (!this.get('isDestroying')) {
28 | next(this, this.propertyDidChange, key);
29 | }
30 | }
31 | };
32 |
33 | args.push(function(key, value, oldValue) {
34 | if (!__onDestroy) {
35 | var _super = this.willDestroy;
36 | this.willDestroy = function() {
37 | cancel(__next);
38 | _super.apply(this);
39 | };
40 | __onDestroy = true;
41 | }
42 | __next = throttle(this, methodFn, key, value, oldValue, rate);
43 | return __value;
44 | });
45 | return computed.apply(this, args);
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/addon/debounced.js:
--------------------------------------------------------------------------------
1 | import Ember from "ember";
2 |
3 | const {
4 | run,
5 | computed
6 | } = Ember;
7 |
8 | const {
9 | debounce,
10 | join,
11 | cancel
12 | } = run;
13 |
14 | export default function debouncedProperty() {
15 |
16 | var args = [].slice.apply(arguments);
17 | var rate = args.pop();
18 | var method = args.pop();
19 |
20 | var __value = null;
21 | var __next = null;
22 | var __onDestroy = false;
23 | var __isNotifying = false;
24 |
25 | var methodFn = function(key, value, oldValue) {
26 |
27 | if (!this.get('isDestroyed')) {
28 | if (!__isNotifying) {
29 | __isNotifying = true;
30 | __value = method.call(this, key, value, oldValue);
31 | if (!this.get('isDestroying')) {
32 | join(this, this.propertyDidChange, key);
33 | }
34 | } else {
35 | __isNotifying = false;
36 | }
37 | }
38 |
39 | };
40 |
41 | args.push(function(key, value, oldValue) {
42 | if (!__onDestroy) {
43 | var _super = this.willDestroy;
44 | this.willDestroy = function() {
45 | cancel(__next);
46 | _super.apply(this);
47 | };
48 | __onDestroy = true;
49 | }
50 | __next = debounce(this, methodFn, key, value, oldValue, rate, false);
51 | return __value;
52 | });
53 | return computed.apply(this, args);
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/tests/dummy/config/environment.js:
--------------------------------------------------------------------------------
1 | /* jshint node: true */
2 |
3 | module.exports = function(environment) {
4 | var ENV = {
5 | modulePrefix: 'dummy',
6 | environment: environment,
7 | baseURL: '/',
8 | locationType: 'hash',
9 | EmberENV: {
10 | FEATURES: {
11 | // Here you can enable experimental features on an ember canary build
12 | // e.g. 'with-controller': true
13 | }
14 | },
15 |
16 | APP: {
17 | // Here you can pass flags/options to your application instance
18 | // when it is created
19 | },
20 |
21 | contentSecurityPolicy: {
22 | 'font-src': "'self' https://maxcdn.bootstrapcdn.com http://fonts.googleapis.com http://fonts.gstatic.com",
23 | 'img-src': "'self' https://maxcdn.bootstrapcdn.com",
24 | 'style-src': "'unsafe-inline' 'self' https://maxcdn.bootstrapcdn.com http://fonts.googleapis.com http://fonts.gstatic.com",
25 | 'media-src': "'self' https://maxcdn.bootstrapcdn.com"
26 | }
27 |
28 | };
29 |
30 | if (environment === 'development') {
31 | // ENV.APP.LOG_RESOLVER = true;
32 | // ENV.APP.LOG_ACTIVE_GENERATION = true;
33 | // ENV.APP.LOG_TRANSITIONS = true;
34 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
35 | // ENV.APP.LOG_VIEW_LOOKUPS = true;
36 | }
37 |
38 | if (environment === 'test') {
39 | // Testem prefers this...
40 | ENV.baseURL = '/';
41 | ENV.locationType = 'none';
42 |
43 | // keep test console output quieter
44 | ENV.APP.LOG_ACTIVE_GENERATION = false;
45 | ENV.APP.LOG_VIEW_LOOKUPS = false;
46 |
47 | ENV.APP.rootElement = '#ember-testing';
48 | }
49 |
50 | if (environment === 'production') {
51 |
52 | }
53 |
54 | return ENV;
55 | };
56 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rate-limit-computed",
3 | "version": "1.0.2",
4 | "description": "Debounced and Throttled Computed Properties for Ember.",
5 | "directories": {
6 | "doc": "doc",
7 | "test": "tests"
8 | },
9 | "scripts": {
10 | "start": "ember server",
11 | "build": "ember build",
12 | "test": "ember test"
13 | },
14 | "homepage": "https://github.com/runspired/rate-limit-computed",
15 | "bugs": "https://github.com/runspired/rate-limit-computed/issues",
16 | "repository": {
17 | "type": "git",
18 | "url": "git@github.com:runspired/rate-limit-computed.git"
19 | },
20 | "engines": {
21 | "node": ">= 0.10.0"
22 | },
23 | "author": {
24 | "name": "Chris Thoburn (@runspired)",
25 | "url": "http://runspired.com"
26 | },
27 | "devDependencies": {
28 | "broccoli-asset-rev": "^2.0.2",
29 | "ember-cli": "0.2.3",
30 | "ember-cli-app-version": "0.3.3",
31 | "ember-cli-content-security-policy": "0.4.0",
32 | "ember-cli-dependency-checker": "0.0.8",
33 | "ember-cli-htmlbars": "0.7.4",
34 | "ember-cli-ic-ajax": "0.1.1",
35 | "ember-cli-inject-live-reload": "^1.3.0",
36 | "ember-cli-qunit": "0.3.10",
37 | "ember-cli-uglify": "1.0.1",
38 | "ember-code-snippet": "^1.0.2",
39 | "ember-data": "1.0.0-beta.16.1",
40 | "ember-disable-prototype-extensions": "^1.0.0",
41 | "ember-export-application-global": "^1.0.2",
42 | "grunt": "0.4.5",
43 | "grunt-bump": "0.0.16",
44 | "grunt-cli": "0.1.13",
45 | "jit-grunt": "0.9.0",
46 | "time-grunt": "1.0.0"
47 | },
48 | "keywords": [
49 | "ember-addon"
50 | ],
51 | "dependencies": {
52 | "ember-cli-babel": "^5.0.0"
53 | },
54 | "ember-addon": {
55 | "configPath": "tests/dummy/config"
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/unit/throttle-test.js:
--------------------------------------------------------------------------------
1 | import Ember from "ember";
2 | import { module, test } from 'qunit';
3 | import startApp from '../helpers/start-app';
4 | var App;
5 |
6 | module('Ember.computed.throttle Integration Tests', {
7 |
8 | beforeEach: function() {
9 | App = startApp();
10 | },
11 |
12 | afterEach: function() {
13 | Ember.run(App, App.destroy);
14 | }
15 |
16 | });
17 |
18 | test("Ember.computed.throttle updates property values correctly", function(assert) {
19 | assert.expect(9);
20 | visit('/');
21 |
22 | var controller = getController('application');
23 |
24 | andThen(function () {
25 |
26 | assert.equal(controller.get('cubedTriggered'), 1, 'The computed property was triggered once during setup.');
27 | assert.equal(find('#cubedValue').text(), '0', 'The Screen reflects the correct initial value.');
28 | assert.equal(controller.get('cubed'), 0, 'The computed property is set correctly during setup.');
29 |
30 | click('#plusOne');
31 |
32 | andThen(function() {
33 | assert.equal(controller.get('cubedTriggered'), 2, 'The computed property triggers correctly.');
34 | assert.equal(find('#cubedValue').text(), '1', 'The Screen reflects the correct updated value.');
35 | assert.equal(controller.get('cubed'), 1, 'The computed property reflects the correct value.');
36 | });
37 |
38 | click('#triggerThree');
39 |
40 | andThen(function() {
41 | assert.equal(controller.get('cubedTriggered'), 3, 'The computed property triggered only once.');
42 | assert.equal(find('#cubedValue').text(), '8', 'The Screen reflects the correct value of 2x2x2.');
43 | assert.equal(controller.get('cubed'), 8, 'The computed property reflects the correct value of 2*2*2.');
44 | });
45 |
46 | });
47 |
48 | });
49 |
50 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /*global module, require*/
2 |
3 | module.exports = function (grunt) {
4 |
5 | // show elapsed time at the end
6 | require('time-grunt')(grunt);
7 |
8 | // load all grunt tasks (currently doesn't work for bump-commit)
9 | require('jit-grunt')(grunt);
10 |
11 | grunt.initConfig({
12 |
13 | config : {},
14 |
15 | pkg : grunt.file.readJSON("package.json"),
16 |
17 | bump: {
18 | options: {
19 | files: ['package.json'],
20 | updateConfigs: ['pkg'],
21 | commit: true,
22 | commitMessage: 'Release version %VERSION%',
23 | commitFiles: ['package.json'],
24 | createTag: true,
25 | tagName: '%VERSION%',
26 | tagMessage: 'Version %VERSION%',
27 | push: true,
28 | pushTo: 'origin',
29 | gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
30 | }
31 | }
32 |
33 | });
34 |
35 | /*
36 | Generate a Release (also creates a build);
37 | */
38 | grunt.registerTask(
39 | 'release',
40 | 'Creates and Publishes a Versioned Release. First arg is target, second arg allows for specific environment.',
41 | function (target) {
42 |
43 | grunt.loadNpmTasks('grunt-bump');
44 | var shouldBump = !!target;
45 |
46 | if (!shouldBump) {
47 | grunt.log.warn('[WARNING] grunt:release – No arguments provided. Version will not be bumped.');
48 | }
49 |
50 | if (shouldBump && !~['patch', 'major', 'minor', 'prerelease', 'git'].indexOf(target)) {
51 | grunt.log.error('[ERROR] grunt:release – "' + target + '" is not a valid semver target for to bump.');
52 | return false;
53 | }
54 |
55 | if (shouldBump) {
56 | grunt.task.run(['bump-only:' + target]);
57 | }
58 |
59 | grunt.task.run([
60 | 'bump-commit'
61 | ]);
62 |
63 | }
64 | );
65 |
66 | };
67 |
--------------------------------------------------------------------------------
/tests/dummy/app/templates/application.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Rate Limited Computed Properties
5 |
6 |
7 |
8 |
9 |
10 | Sometimes you need to debounce or throttle a computed property. In the past,
11 | doing so would usually require using an observer instead.
12 |
13 |
14 | You'll still need to make sure your `computed.debounce` or `computed.throttle` are
15 | consumed somewhere, else they won't ever be updated.
16 |
17 |
18 |
19 |
20 | | Count | {{count}} |
21 |
22 |
23 | | Squared | {{squared}} |
24 |
25 |
26 | | Cubed | {{cubed}} |
27 |
28 |
29 | | Squared Triggered | {{squaredTriggered}} |
30 |
31 |
32 | | CubedTriggered | {{cubedTriggered}} |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
Controller code for this example
43 |
44 | {{code-snippet name="debounce-throttle-example.js"}}
45 |
46 |
47 |
48 |
49 | {{outlet}}
50 |
--------------------------------------------------------------------------------
/tests/unit/debounce-test.js:
--------------------------------------------------------------------------------
1 | import Ember from "ember";
2 | import { module, test } from 'qunit';
3 | import startApp from '../helpers/start-app';
4 | var App;
5 |
6 | module('Ember.computed.debounce Integration Tests', {
7 |
8 | beforeEach: function() {
9 | App = startApp();
10 | },
11 |
12 | afterEach: function() {
13 | Ember.run(App, App.destroy);
14 | }
15 |
16 | });
17 |
18 | test("Ember.computed.debounce updates property values correctly", function(assert) {
19 | assert.expect(12);
20 | visit('/');
21 |
22 | var controller = getController('application');
23 |
24 | andThen(function () {
25 |
26 | assert.equal(controller.get('count'), 0, 'The count begins at 0');
27 | assert.equal(controller.get('squaredTriggered'), 1, 'The computed property was triggered once during setup.');
28 | assert.equal(find('#squaredValue').text(), '0', 'The Screen reflects the correct initial value.');
29 | assert.equal(controller.get('squared'), 0, 'The computed property is set correctly during setup.');
30 |
31 | click('#plusOne');
32 |
33 | andThen(function() {
34 | assert.equal(controller.get('count'), 1, 'The count was incremented to 1.');
35 | assert.equal(controller.get('squaredTriggered'), 2, 'The computed property triggers correctly.');
36 | assert.equal(find('#squaredValue').text(), '1', 'The Screen reflects the correct updated value.');
37 | assert.equal(controller.get('squared'), 1, 'The computed property reflects the correct value.');
38 | });
39 |
40 | click('#triggerThree');
41 |
42 | andThen(function() {
43 | assert.equal(controller.get('count'), 4, 'The count was incremented to 4.');
44 | assert.equal(controller.get('squaredTriggered'), 3, 'The computed property triggered only once.');
45 | assert.equal(find('#squaredValue').text(), '16', 'The Screen reflects the correct value of 4x4.');
46 | assert.equal(controller.get('squared'), 16, 'The computed property reflects the correct value of 4x4.');
47 | });
48 |
49 | });
50 |
51 | });
52 |
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rate-limit-computed
2 |
3 |
4 | [](http://badge.fury.io/js/rate-limit-computed)
5 | [](https://travis-ci.org/runspired/rate-limit-computed)
6 | [](http://emberobserver.com/addons/rate-limit-computed)
7 | [](https://circleci.com/gh/runspired/rate-limit-computed/tree/master)
8 |
9 | Ember addon for debouncing or throttling a computed property. Interactive
10 | documentation is here: [http://runspired.github.io/rate-limit-computed/](http://runspired.github.io/rate-limit-computed/).
11 |
12 |
13 | Sometimes you need to debounce or throttle a computed property. In the past, doing
14 | so would usually require using an observer instead.
15 |
16 | You'll still need to make sure your `computed.debounce` or `computed.throttle` are
17 | consumed somewhere, else they won't ever be updated.
18 |
19 | [](https://david-dm.org/runspired/rate-limit-computed)
20 | [](https://david-dm.org/runspired/rate-limit-computed#info=devDependencies)
21 |
22 |
23 | ## Installation
24 |
25 | If you are on a recent version of `ember-cli`, do the following:
26 |
27 | ember install rate-limit-computed
28 |
29 |
30 | This is the equivalent of:
31 |
32 | npm install --save-dev rate-limit-computed
33 |
34 | ## Usage
35 |
36 | import Ember from "ember";
37 |
38 | const {
39 | computed
40 | } = Ember;
41 |
42 | export default Ember.Component.extend({
43 |
44 | cubed: computed.throttle('foo', function() {
45 | var foo = this.get('foo');
46 | return foo * foo * foo;
47 | }, 16)
48 |
49 | count: 0,
50 |
51 | });
52 |
53 |
54 |
55 | In your template, you use the computed property just like normal.
56 |
57 |
58 | {{cubed}}
59 |
60 |
--------------------------------------------------------------------------------