Skip to content

Commit

Permalink
Improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed Dec 21, 2024
1 parent ac61c72 commit 5904540
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions content/snippets/js/s/complex-object-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ export default class Serializer {
// ...

serialize() {
return this.constructor.serializableAttributes.reduce((acc, attribute) => {
acc[attribute] = this.subject[attribute];
return acc;
}, {});
return this.constructor.serializableAttributes.reduce(
(acc, attribute) => {
acc[attribute] = this.subject[attribute];
return acc;
},
{},
);
}
}
```
Expand Down Expand Up @@ -213,10 +216,13 @@ export default class Serializer {
// ...

serialize() {
return this.constructor.serializableAttributes.reduce((acc, attribute) => {
acc[attribute] = this[attribute];
return acc;
}, {});
return this.constructor.serializableAttributes.reduce(
(acc, attribute) => {
acc[attribute] = this[attribute];
return acc;
},
{},
);
}
}
```
Expand Down Expand Up @@ -592,7 +598,7 @@ export default class Serializer {
static prepare(serializer, serializableAttributes) {
serializer.serializableAttributes = [];

serializableAttributes.forEach(attribute => {
serializableAttributes.forEach((attribute) => {
const isAlias = Array.isArray(attribute);
const attributeName = isAlias ? attribute[0] : attribute;

Expand All @@ -604,11 +610,9 @@ export default class Serializer {

Object.defineProperty(serializer.prototype, attributeName, {
get() {
if (!isAlias)
return this.subject[attributeName];
if (typeof alias === 'string')
return this.subject[alias];
if (typeof alias === 'function')
if (!isAlias) return this.subject[attributeName];
if (typeof alias === "string") return this.subject[alias];
if (typeof alias === "function")
return alias(this.subject, this.options);
return undefined;
},
Expand All @@ -626,14 +630,17 @@ export default class Serializer {
}

static serializeArray(subjects, options) {
return subjects.map(subject => this.serialize(subject, options));
return subjects.map((subject) => this.serialize(subject, options));
}

serialize() {
return this.constructor.serializableAttributes.reduce((acc, attribute) => {
acc[attribute] = this[attribute];
return acc;
}, {});
return this.constructor.serializableAttributes.reduce(
(acc, attribute) => {
acc[attribute] = this[attribute];
return acc;
},
{},
);
}
}
```
Expand Down

0 comments on commit 5904540

Please sign in to comment.