Skip to content

Commit

Permalink
Refactor #4384
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Sep 5, 2023
1 parent e49179b commit 57ce4e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions components/lib/basecomponent/BaseComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export default {
const searchOut = /./g.test(key) && !!params[key.split('.')[0]];
const { mergeSections = true, mergeProps: useMergeProps = false } = this.ptOptions || {};
const global = searchInDefaultPT ? (searchOut ? this._useGlobalPT(this._getPTClassValue, key, params) : this._useDefaultPT(this._getPTClassValue, key, params)) : undefined;
const self = searchOut ? undefined : this._usePT(this._getPT(obj, this.$name), this._getPTClassValue, key, { ...params, global });
const self = searchOut ? undefined : this._usePT(this._getPT(obj, this.$name), this._getPTClassValue, key, { ...params, global: global || {} });
const datasets = key !== 'transition' && {
...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.toFlatCase(this.$.type.name) }),
[`${datasetPrefix}section`]: ObjectUtils.toFlatCase(key)
Expand All @@ -486,12 +486,12 @@ export default {
_getPT(pt, key = '', callback) {
const _usept = pt?.['_usept'];
const getValue = (value) => {
const getValue = (value, checkSameKey = false) => {
const computedValue = callback ? callback(value) : value;
const _key = ObjectUtils.toFlatCase(key);
const _cKey = ObjectUtils.toFlatCase(this.$name);
return (_key !== _cKey ? computedValue?.[_key] : undefined) ?? computedValue;
return (checkSameKey ? (_key !== _cKey ? computedValue?.[_key] : undefined) : computedValue?.[_key]) ?? computedValue;
};
return ObjectUtils.isNotEmpty(_usept)
Expand All @@ -500,13 +500,13 @@ export default {
originalValue: getValue(pt.originalValue),
value: getValue(pt.value)
}
: getValue(pt);
: getValue(pt, true);
},
_usePT(pt, callback, key, params) {
const fn = (value) => callback(value, key, params);
if (pt?.hasOwnProperty('_usept')) {
const { mergeSections = true, mergeProps: useMergeProps = false } = this.ptOptions || pt['_usept'] || {};
const { mergeSections = true, mergeProps: useMergeProps = false } = pt['_usept'] || {};
const originalValue = fn(pt.originalValue);
const value = fn(pt.value);
Expand Down
7 changes: 4 additions & 3 deletions components/lib/basedirective/BaseDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BaseDirective = {
const datasetPrefix = 'data-pc-';
const { mergeSections = true, mergeProps: useMergeProps = false } = instance.binding?.value?.ptOptions || {};
const global = searchInDefaultPT ? BaseDirective._useDefaultPT(instance, instance.defaultPT, getValue, key, params) : undefined;
const self = BaseDirective._usePT(instance, BaseDirective._getPT(obj, instance.$name), getValue, key, { ...params, global });
const self = BaseDirective._usePT(instance, BaseDirective._getPT(obj, instance.$name), getValue, key, { ...params, global: global || {} });
const datasets = {
...(key === 'root' && { [`${datasetPrefix}name`]: ObjectUtils.toFlatCase(instance.$name) }),
[`${datasetPrefix}section`]: ObjectUtils.toFlatCase(key)
Expand All @@ -37,8 +37,9 @@ const BaseDirective = {

const getValue = (value) => {
const computedValue = callback ? callback(value) : value;
const _key = ObjectUtils.toFlatCase(key);

return computedValue?.[ObjectUtils.toFlatCase(key)] ?? computedValue;
return computedValue?.[_key] ?? computedValue;
};

return ObjectUtils.isNotEmpty(_usept)
Expand All @@ -53,7 +54,7 @@ const BaseDirective = {
const fn = (value) => callback(value, key, params);

if (pt?.hasOwnProperty('_usept')) {
const { mergeSections = true, mergeProps: useMergeProps = false } = instance.binding?.value?.ptOptions || pt['_usept'] || {};
const { mergeSections = true, mergeProps: useMergeProps = false } = pt['_usept'] || {};
const originalValue = fn(pt.originalValue);
const value = fn(pt.value);

Expand Down

0 comments on commit 57ce4e0

Please sign in to comment.