From 96b677434b817e87c8b17a68de31b6888625b6b9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 18 Nov 2019 21:44:02 -0800 Subject: [PATCH] Remove usage of fromEntries --- module/actor-sheet.js | 17 +++++++++-------- module/item-sheet.js | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index c85c46e..06649da 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -118,12 +118,12 @@ export class SimpleActorSheet extends ActorSheet { // Handle the free-form attributes list const formAttrs = expandObject(formData).data.attributes || {}; - const attributes = Object.fromEntries(Object.entries(formAttrs).map(attr => { - let [k, v] = attr; - k = v["key"].trim(); + const attributes = Object.values(formAttrs).reduce((obj, v) => { + let k = v["key"].trim(); delete v["key"]; - return [k, v]; - })); + obj[k] = v; + return obj; + }, {}); // Remove attributes which are no longer used for ( let k of Object.keys(this.object.data.data.attributes) ) { @@ -131,9 +131,10 @@ export class SimpleActorSheet extends ActorSheet { } // Re-combine formData - formData = Object.fromEntries(Object.entries(formData).filter(a => !a[0].startsWith("data.attributes"))); - formData["_id"] = this.object._id; - formData["data.attributes"] = attributes; + formData = Object.entries(formData).filter(e => !e[0].startsWith("data.attributes")).reduce((obj, e) => { + obj[e[0]] = e[1]; + return obj; + }, {_id: this.object._id, "data.attributes": attributes}); // Update the Actor return this.object.update(formData); diff --git a/module/item-sheet.js b/module/item-sheet.js index 88e5cc8..1d6b99e 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -102,12 +102,12 @@ export class SimpleItemSheet extends ItemSheet { // Handle the free-form attributes list const formAttrs = expandObject(formData).data.attributes || {}; - const attributes = Object.fromEntries(Object.entries(formAttrs).map(attr => { - let [k, v] = attr; - k = v["key"].trim(); + const attributes = Object.values(formAttrs).reduce((obj, v) => { + let k = v["key"].trim(); delete v["key"]; - return [k, v]; - })); + obj[k] = v; + return obj; + }, {}); // Remove attributes which are no longer used for ( let k of Object.keys(this.object.data.data.attributes) ) { @@ -115,10 +115,11 @@ export class SimpleItemSheet extends ItemSheet { } // Re-combine formData - formData = Object.fromEntries(Object.entries(formData).filter(a => !a[0].startsWith("data.attributes"))); - formData["_id"] = this.object._id; - formData["data.attributes"] = attributes; - + formData = Object.entries(formData).filter(e => !e[0].startsWith("data.attributes")).reduce((obj, e) => { + obj[e[0]] = e[1]; + return obj; + }, {_id: this.object._id, "data.attributes": attributes}); + // Update the Item return this.object.update(formData); }