Remove usage of fromEntries

This commit is contained in:
Andrew 2019-11-18 21:44:02 -08:00
parent fc8331c13c
commit 96b677434b
2 changed files with 19 additions and 17 deletions

View file

@ -118,12 +118,12 @@ export class SimpleActorSheet extends ActorSheet {
// Handle the free-form attributes list // Handle the free-form attributes list
const formAttrs = expandObject(formData).data.attributes || {}; const formAttrs = expandObject(formData).data.attributes || {};
const attributes = Object.fromEntries(Object.entries(formAttrs).map(attr => { const attributes = Object.values(formAttrs).reduce((obj, v) => {
let [k, v] = attr; let k = v["key"].trim();
k = v["key"].trim();
delete v["key"]; delete v["key"];
return [k, v]; obj[k] = v;
})); return obj;
}, {});
// Remove attributes which are no longer used // Remove attributes which are no longer used
for ( let k of Object.keys(this.object.data.data.attributes) ) { for ( let k of Object.keys(this.object.data.data.attributes) ) {
@ -131,9 +131,10 @@ export class SimpleActorSheet extends ActorSheet {
} }
// Re-combine formData // Re-combine formData
formData = Object.fromEntries(Object.entries(formData).filter(a => !a[0].startsWith("data.attributes"))); formData = Object.entries(formData).filter(e => !e[0].startsWith("data.attributes")).reduce((obj, e) => {
formData["_id"] = this.object._id; obj[e[0]] = e[1];
formData["data.attributes"] = attributes; return obj;
}, {_id: this.object._id, "data.attributes": attributes});
// Update the Actor // Update the Actor
return this.object.update(formData); return this.object.update(formData);

View file

@ -102,12 +102,12 @@ export class SimpleItemSheet extends ItemSheet {
// Handle the free-form attributes list // Handle the free-form attributes list
const formAttrs = expandObject(formData).data.attributes || {}; const formAttrs = expandObject(formData).data.attributes || {};
const attributes = Object.fromEntries(Object.entries(formAttrs).map(attr => { const attributes = Object.values(formAttrs).reduce((obj, v) => {
let [k, v] = attr; let k = v["key"].trim();
k = v["key"].trim();
delete v["key"]; delete v["key"];
return [k, v]; obj[k] = v;
})); return obj;
}, {});
// Remove attributes which are no longer used // Remove attributes which are no longer used
for ( let k of Object.keys(this.object.data.data.attributes) ) { for ( let k of Object.keys(this.object.data.data.attributes) ) {
@ -115,10 +115,11 @@ export class SimpleItemSheet extends ItemSheet {
} }
// Re-combine formData // Re-combine formData
formData = Object.fromEntries(Object.entries(formData).filter(a => !a[0].startsWith("data.attributes"))); formData = Object.entries(formData).filter(e => !e[0].startsWith("data.attributes")).reduce((obj, e) => {
formData["_id"] = this.object._id; obj[e[0]] = e[1];
formData["data.attributes"] = attributes; return obj;
}, {_id: this.object._id, "data.attributes": attributes});
// Update the Item // Update the Item
return this.object.update(formData); return this.object.update(formData);
} }