From 8d4631526cde85d6cfe148313b4963c25fdabce2 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 1 Apr 2020 09:55:20 +0100 Subject: [PATCH] ui: Fix token duplication bug (#7552) We need to detect whether an object is an ember-data snapshot or just a plain object, and we where restricted from using `instanceof` due to ember-data's `Snapshot` class being private. We'd chosen to go with `constructor.name` instead, which seemed to work, but when the javascript gets minifed the name of the contructor is also minified and therefore is not what you are expecting. This commit reverts to our original idea of checking for the existence and type of the `.attributes` function, which is the function we require within the conditional, and therefore is more reliable (if the function doesn't exist it will error out during development aswell as production) --- ui-v2/app/adapters/application.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui-v2/app/adapters/application.js b/ui-v2/app/adapters/application.js index b9cea8cf1f..685d862b90 100644 --- a/ui-v2/app/adapters/application.js +++ b/ui-v2/app/adapters/application.js @@ -29,8 +29,13 @@ export default Adapter.extend({ let unserialized, serialized; const serializer = store.serializerFor(modelName); // workable way to decide whether this is a snapshot + // essentially 'is attributable'. // Snapshot is private so we can't do instanceof here - if (obj.constructor.name === 'Snapshot') { + // and using obj.constructor.name gets changed/minified + // during compilation so you can't rely on it + // checking for `attributes` being a function is more + // reliable as that is the thing we need to call + if (typeof obj.attributes === 'function') { unserialized = obj.attributes(); serialized = serializer.serialize(obj, {}); } else {