REFACTOR: Remove discourse/lib/throttle

This commit is contained in:
Robin Ward 2019-11-11 13:19:59 -05:00
parent 4ddb69e9c6
commit e8dae447bd
3 changed files with 13 additions and 30 deletions

View File

@ -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

View File

@ -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);
};
}

View File

@ -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"),