mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 23:43:45 +08:00
DEV: prefer Date.now() over new Date().getTime()
`New Date().getTime()` is both uglier and slower than `Date.now()` `Date.now()` is available on all the browsers we support.
This commit is contained in:
parent
25f1f23288
commit
e62071830d
|
@ -112,7 +112,7 @@ export default Component.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const t0 = new Date().getTime();
|
const t0 = Date.now();
|
||||||
const args = this.args || this.buildArgs();
|
const args = this.args || this.buildArgs();
|
||||||
const opts = {
|
const opts = {
|
||||||
model: this.model,
|
model: this.model,
|
||||||
|
@ -139,7 +139,7 @@ export default Component.extend({
|
||||||
|
|
||||||
if (this.profileWidget) {
|
if (this.profileWidget) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(new Date().getTime() - t0);
|
console.log(Date.now() - t0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default Component.extend({
|
||||||
},
|
},
|
||||||
hideForSession() {
|
hideForSession() {
|
||||||
this.session.set("hideSignupCta", true);
|
this.session.set("hideSignupCta", true);
|
||||||
this.keyValueStore.setItem("anon-cta-hidden", new Date().getTime());
|
this.keyValueStore.setItem("anon-cta-hidden", Date.now());
|
||||||
later(() => this.session.set("showSignupCta", false), 20 * 1000);
|
later(() => this.session.set("showSignupCta", false), 20 * 1000);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default {
|
||||||
return; // hidden forever
|
return; // hidden forever
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date().getTime();
|
const now = Date.now();
|
||||||
const hiddenAt = keyValueStore.getInt("anon-cta-hidden", 0);
|
const hiddenAt = keyValueStore.getInt("anon-cta-hidden", 0);
|
||||||
if (hiddenAt > now - PROMPT_HIDE_DURATION) {
|
if (hiddenAt > now - PROMPT_HIDE_DURATION) {
|
||||||
return; // hidden in last 24 hours
|
return; // hidden in last 24 hours
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default class LockOn {
|
||||||
}
|
}
|
||||||
|
|
||||||
lock() {
|
lock() {
|
||||||
const startedAt = new Date().getTime();
|
const startedAt = Date.now();
|
||||||
let previousTop = this.elementTop();
|
let previousTop = this.elementTop();
|
||||||
previousTop && $(window).scrollTop(previousTop);
|
previousTop && $(window).scrollTop(previousTop);
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ export default class LockOn {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop after a little while
|
// Stop after a little while
|
||||||
if (new Date().getTime() - startedAt > LOCK_DURATION_MS) {
|
if (Date.now() - startedAt > LOCK_DURATION_MS) {
|
||||||
return this.clearLock(interval);
|
return this.clearLock(interval);
|
||||||
}
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
|
@ -65,7 +65,7 @@ export default class {
|
||||||
|
|
||||||
// Reset our timers
|
// Reset our timers
|
||||||
reset() {
|
reset() {
|
||||||
const now = new Date().getTime();
|
const now = Date.now();
|
||||||
this._lastTick = now;
|
this._lastTick = now;
|
||||||
this._lastScrolled = now;
|
this._lastScrolled = now;
|
||||||
this._lastFlush = 0;
|
this._lastFlush = 0;
|
||||||
|
@ -79,7 +79,7 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
scrolled() {
|
scrolled() {
|
||||||
this._lastScrolled = new Date().getTime();
|
this._lastScrolled = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
registerAnonCallback(cb) {
|
registerAnonCallback(cb) {
|
||||||
|
@ -212,7 +212,7 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
const now = new Date().getTime();
|
const now = Date.now();
|
||||||
|
|
||||||
// If the user hasn't scrolled the browser in a long time, stop tracking time read
|
// If the user hasn't scrolled the browser in a long time, stop tracking time read
|
||||||
const sinceScrolled = now - this._lastScrolled;
|
const sinceScrolled = now - this._lastScrolled;
|
||||||
|
|
|
@ -368,7 +368,7 @@ const DiscourseURL = EmberObject.extend({
|
||||||
const closest = postStream.closestPostNumberFor(opts.nearPost || 1);
|
const closest = postStream.closestPostNumberFor(opts.nearPost || 1);
|
||||||
topicController.setProperties({
|
topicController.setProperties({
|
||||||
"model.currentPost": closest,
|
"model.currentPost": closest,
|
||||||
enteredAt: new Date().getTime().toString()
|
enteredAt: Date.now().toString()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.appEvents.trigger("post:highlight", closest);
|
this.appEvents.trigger("post:highlight", closest);
|
||||||
|
|
|
@ -61,7 +61,7 @@ export default Mixin.create({
|
||||||
if (e.type === "pointerup" || e.type === "pointercancel") {
|
if (e.type === "pointerup" || e.type === "pointercancel") {
|
||||||
return oldState;
|
return oldState;
|
||||||
}
|
}
|
||||||
const newTimestamp = new Date().getTime();
|
const newTimestamp = Date.now();
|
||||||
const timeDiffSeconds = newTimestamp - oldState.timestamp;
|
const timeDiffSeconds = newTimestamp - oldState.timestamp;
|
||||||
if (timeDiffSeconds === 0) {
|
if (timeDiffSeconds === 0) {
|
||||||
return oldState;
|
return oldState;
|
||||||
|
@ -109,7 +109,7 @@ export default Mixin.create({
|
||||||
deltaY: 0,
|
deltaY: 0,
|
||||||
distance: 0,
|
distance: 0,
|
||||||
start: true,
|
start: true,
|
||||||
timestamp: new Date().getTime(),
|
timestamp: Date.now(),
|
||||||
direction: null
|
direction: null
|
||||||
};
|
};
|
||||||
this.set("_panState", newState);
|
this.set("_panState", newState);
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default DiscourseRoute.extend({
|
||||||
topicController.setProperties({
|
topicController.setProperties({
|
||||||
"model.currentPost": closest,
|
"model.currentPost": closest,
|
||||||
enteredIndex: topic.postStream.progressIndexOfPost(closestPost),
|
enteredIndex: topic.postStream.progressIndexOfPost(closestPost),
|
||||||
enteredAt: new Date().getTime().toString()
|
enteredAt: Date.now().toString()
|
||||||
});
|
});
|
||||||
|
|
||||||
this.appEvents.trigger("page:topic-loaded", topic);
|
this.appEvents.trigger("page:topic-loaded", topic);
|
||||||
|
|
|
@ -13,7 +13,7 @@ export function historyHeat(siteSettings, updatedAt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show heat on age
|
// Show heat on age
|
||||||
const rightNow = new Date().getTime();
|
const rightNow = Date.now();
|
||||||
const updatedAtTime = updatedAt.getTime();
|
const updatedAtTime = updatedAt.getTime();
|
||||||
|
|
||||||
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_low)) {
|
if (updatedAtTime > rightNow - mult(siteSettings.history_hours_low)) {
|
||||||
|
|
|
@ -730,7 +730,7 @@ export default createWidget("post", {
|
||||||
const lastWarnedLikes = kvs.get("lastWarnedLikes");
|
const lastWarnedLikes = kvs.get("lastWarnedLikes");
|
||||||
|
|
||||||
// only warn once per day
|
// only warn once per day
|
||||||
const yesterday = new Date().getTime() - 1000 * 60 * 60 * 24;
|
const yesterday = Date.now() - 1000 * 60 * 60 * 24;
|
||||||
if (lastWarnedLikes && parseInt(lastWarnedLikes, 10) > yesterday) {
|
if (lastWarnedLikes && parseInt(lastWarnedLikes, 10) > yesterday) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -739,7 +739,7 @@ export default createWidget("post", {
|
||||||
const threshold = Math.ceil(max * 0.1);
|
const threshold = Math.ceil(max * 0.1);
|
||||||
if (remaining === threshold) {
|
if (remaining === threshold) {
|
||||||
bootbox.alert(I18n.t("post.few_likes_left"));
|
bootbox.alert(I18n.t("post.few_likes_left"));
|
||||||
kvs.set({ key: "lastWarnedLikes", value: new Date().getTime() });
|
kvs.set({ key: "lastWarnedLikes", value: Date.now() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user