DEV: polyfill Object.values and use where needed

We now have polyfills for `values` IE and `entries` IE

This commit uses values where appropriate to eliminate an extra lookup
This simplifies the code a bit.

Followup to: 7f089f07a7
This commit is contained in:
Sam 2018-11-28 10:07:05 +11:00
parent 3cb88bc566
commit 912a7105d2
5 changed files with 17 additions and 8 deletions

View File

@ -526,9 +526,7 @@ export default Ember.Component.extend({
post.set("refreshedPost", true);
}
Object.keys(oneboxes).forEach(oneboxURL => {
const onebox = oneboxes[oneboxURL];
Object.values(oneboxes).forEach(onebox => {
onebox.forEach($onebox => {
load({
elem: $onebox,

View File

@ -252,7 +252,7 @@ export default MountWidget.extend({
uncloak(post, this);
});
Object.keys(prev).forEach(pn => cloak(prev[pn], this));
Object.values(prev).forEach(node => cloak(node, this));
this._previouslyNearby = newPrev;
this.screenTrack.setOnscreen(onscreenPostNumbers);

View File

@ -373,8 +373,7 @@ const TopicTrackingState = Discourse.Model.extend({
countCategory(category_id) {
let sum = 0;
Object.keys(this.states).forEach(topicState => {
const topic = this.states[topicState];
Object.values(this.states).forEach(topic => {
if (topic.category_id === category_id && !topic.deleted) {
sum +=
topic.last_read_post_number === null ||

View File

@ -404,8 +404,7 @@ export default createWidget("post-menu", {
])
);
Object.keys(_extraButtons).forEach(k => {
const builder = _extraButtons[k];
Object.values(_extraButtons).forEach(builder => {
if (builder) {
const buttonAtts = builder(attrs, this.state, this.siteSettings);
if (buttonAtts) {

View File

@ -10,6 +10,19 @@ if (!Object.entries) {
};
}
// adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
// missing in ie only
if (!Object.values) {
Object.values = function(obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--) resArray[i] = obj[ownProps[i]];
return resArray;
};
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
if (typeof Object.assign !== "function") {
// Must be writable: true, enumerable: false, configurable: true