Browse Source
Add skip resolve (#6547)
* Add skip resolve option to traits
* Add skip resolve to get Attributes
* add ts docs for the new trait option
pull/6553/head
mohamed yahia
8 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
16 additions and
3 deletions
-
packages/core/src/dom_components/model/Component.ts
-
packages/core/src/trait_manager/model/Trait.ts
-
packages/core/src/trait_manager/types.ts
|
|
|
@ -867,10 +867,14 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
* Return all component's attributes |
|
|
|
* @return {Object} |
|
|
|
*/ |
|
|
|
getAttributes(opts: { noClass?: boolean; noStyle?: boolean } = {}) { |
|
|
|
getAttributes(opts: { noClass?: boolean; noStyle?: boolean; skipResolve?: boolean } = {}) { |
|
|
|
const { em } = this; |
|
|
|
const classes: string[] = []; |
|
|
|
const attributes = { ...this.get('attributes') }; |
|
|
|
const dynamicValues = opts.skipResolve ? this.dataResolverWatchers.getDynamicAttributesDefs() : {}; |
|
|
|
const attributes = { |
|
|
|
...this.get('attributes'), |
|
|
|
...dynamicValues, |
|
|
|
}; |
|
|
|
const sm = em?.Selectors; |
|
|
|
const id = this.getId(); |
|
|
|
|
|
|
|
|
|
|
|
@ -266,6 +266,7 @@ export default class Trait extends Model<TraitProperties> { |
|
|
|
const getValue = this.get('getValue'); |
|
|
|
let value; |
|
|
|
|
|
|
|
const skipResolve = opts.skipResolve; |
|
|
|
if (getValue) { |
|
|
|
value = getValue({ |
|
|
|
editor: em?.getEditor()!, |
|
|
|
@ -274,8 +275,9 @@ export default class Trait extends Model<TraitProperties> { |
|
|
|
}); |
|
|
|
} else if (this.changeProp) { |
|
|
|
value = component.get(name); |
|
|
|
if (skipResolve) value = component.dataResolverWatchers.getPropsDefsOrValues({ [name]: value })[name]; |
|
|
|
} else { |
|
|
|
value = component.getAttributes()[name]; |
|
|
|
value = component.getAttributes({ skipResolve })[name]; |
|
|
|
} |
|
|
|
|
|
|
|
if (opts.useType) { |
|
|
|
|
|
|
|
@ -162,6 +162,13 @@ export interface TraitGetValueOptions { |
|
|
|
* @default false |
|
|
|
*/ |
|
|
|
useType?: boolean; |
|
|
|
|
|
|
|
/** |
|
|
|
* If false, return the value |
|
|
|
* If true and the value is a data resolver, return the data resolver props |
|
|
|
* @default false |
|
|
|
*/ |
|
|
|
skipResolve?: boolean; |
|
|
|
} |
|
|
|
|
|
|
|
export interface TraitOption { |
|
|
|
|