Skip to content

Commit

Permalink
feat: use getSafePropertyChain utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
annacv committed Nov 7, 2023
1 parent 9543790 commit 9498705
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/composables/use-experience-controls.composable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, ComputedRef, inject } from 'vue';
import { Dictionary } from '@empathyco/x-utils';
import { Dictionary, getSafePropertyChain } from '@empathyco/x-utils';

/**
* Given a controls' object property chain, gets the experience controls values from the response.
Expand All @@ -18,10 +18,7 @@ export const useXControlsHelpers = ({
}): ComputedRef => {
const experienceControls = inject<Dictionary>('experienceControls', {});

const getByPath = function <T>(this: T, key: string): any {
return key.split('.').reduce((obj, prop) => (obj as any)[prop], this);
};
return computed(() => {
return getByPath.call(experienceControls.value?.controls, path) ?? defaultValue;
return getSafePropertyChain(experienceControls.value.controls, path, defaultValue);
});
};

0 comments on commit 9498705

Please sign in to comment.