refactor: sort trait keys

This commit is contained in:
cha0s 2021-01-28 01:01:50 -06:00
parent bdd5152e77
commit 5f189009b9

View File

@ -71,12 +71,26 @@ export default class EntityController extends JsonResourceController {
static decode(encoded, latus) {
const {Entity} = latus.get('%resources');
return super.decode(Entity.withoutDefaults(encoded));
const json = Entity.withoutDefaults(encoded);
return super.decode({
...json,
traits: Object.fromEntries(
Object.entries(json.traits)
.sort(([l], [r]) => (l < r ? -1 : 1)),
),
});
}
static encode(buffer, latus) {
const {Entity} = latus.get('%resources');
return Entity.withDefaults(super.encode(buffer));
const json = Entity.withDefaults(super.encode(buffer));
return {
...json,
traits: Object.fromEntries(
Object.entries(json.traits)
.sort(([l], [r]) => (l < r ? -1 : 1)),
),
};
}
static get matcher() {