From 96b164661407a8560dbce1d4db5d3801741c3b47 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 21 Oct 2021 11:39:53 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20simplify/improve=20e?= =?UTF-8?q?valuator=20record=20serialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/helpers/bexpr-filter.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/addons/api/mirage/helpers/bexpr-filter.js b/addons/api/mirage/helpers/bexpr-filter.js index e2cffef02..8b12fe178 100644 --- a/addons/api/mirage/helpers/bexpr-filter.js +++ b/addons/api/mirage/helpers/bexpr-filter.js @@ -1,19 +1,7 @@ import { makeEvaluator } from 'js-bexpr'; -import { underscore } from '@ember/string'; +import SessionSerializer from '../serializers/session'; -/** - * Because Mirage, a record cannot be serialized outside of a route handler - * context. Here is a quick and dirty attempt to serialize attribute names - * to underscore format. This is not entirely realistic, but may suffice. - */ -const quickSerialize = (item) => { - const json = item.toJSON(); - Object.keys(json).forEach((key) => { - const newKey = underscore(key); - json[newKey] = json[key]; - }); - return json; -}; +const serializer = new SessionSerializer(); /** * Creates a filter function that operates on a single object, which itself @@ -24,7 +12,7 @@ export default (expression) => { const evaluator = makeEvaluator(expression); // Since API query selectors begin with `/item`, the instance is wrapped. return (item) => { - const json = quickSerialize(item); + const json = serializer.serialize(item); return evaluator({ item: json }); }; } else {