From e8dae447bdb34df61b9fcebe8dc4b3695a5f0c3a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 11 Nov 2019 13:19:59 -0500 Subject: [PATCH] REFACTOR: Remove `discourse/lib/throttle` --- app/assets/javascripts/application.js | 1 - .../javascripts/discourse/lib/throttle.js.es6 | 19 --------------- .../discourse/models/composer.js.es6 | 23 +++++++++++-------- 3 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 app/assets/javascripts/discourse/lib/throttle.js.es6 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 10c71ca89b7..6dbb9e815ca 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -26,7 +26,6 @@ //= require ./discourse/lib/lock-on //= require ./discourse/lib/url //= require ./discourse/lib/debounce -//= require ./discourse/lib/throttle //= require ./discourse/lib/quote //= require ./discourse/lib/key-value-store //= require ./discourse/lib/computed diff --git a/app/assets/javascripts/discourse/lib/throttle.js.es6 b/app/assets/javascripts/discourse/lib/throttle.js.es6 deleted file mode 100644 index 05daa36c5a6..00000000000 --- a/app/assets/javascripts/discourse/lib/throttle.js.es6 +++ /dev/null @@ -1,19 +0,0 @@ -import { throttle } from "@ember/runloop"; -/** - Throttle a Javascript function. This means if it's called many times in a time limit it - should only be executed one time at most during this time limit - Original function will be called with the context and arguments from the last call made. -**/ -export default function(func, spacing, immediate) { - let self, args; - const later = function() { - func.apply(self, args); - }; - - return function() { - self = this; - args = arguments; - - throttle(null, later, spacing, immediate); - }; -} diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 60fb8272a6c..afa1bf732c5 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -16,7 +16,7 @@ import { } from "discourse-common/utils/decorators"; import { escapeExpression, tinyAvatar } from "discourse/lib/utilities"; import { propertyNotEqual } from "discourse/lib/computed"; -import throttle from "discourse/lib/throttle"; +import { throttle } from "@ember/runloop"; import { Promise } from "rsvp"; import { set } from "@ember/object"; @@ -226,15 +226,18 @@ const Composer = RestModel.extend({ return this.set("metaData", EmberObject.create()); }, - // view detected user is typing - typing: throttle( - function() { - const typingTime = this.typingTime || 0; - this.set("typingTime", typingTime + 100); - }, - 100, - false - ), + // called whenever the user types to update the typing time + typing() { + throttle( + this, + function() { + const typingTime = this.typingTime || 0; + this.set("typingTime", typingTime + 100); + }, + 100, + false + ); + }, editingFirstPost: and("editingPost", "post.firstPost"),