Browse Source

cleanup and refactor

pull/6351/head
mohamedsalem401 2 years ago
parent
commit
a74854fb4e
  1. 1
      packages/core/src/common/index.ts
  2. 35
      packages/core/src/dom_components/model/Component.ts

1
packages/core/src/common/index.ts

@ -9,7 +9,6 @@ export const collectionEvents = 'add remove reset change';
export type Debounced = Function & { cancel(): void };
export type SetOptions = Backbone.ModelSetOptions & {
unset?: boolean;
avoidStore?: boolean;
avoidTransformers?: boolean;
partial?: boolean;

35
packages/core/src/dom_components/model/Component.ts

@ -337,33 +337,34 @@ export default class Component extends StyleableModel<ComponentProperties> {
}
}
set<A extends string>(attributeName: A, value?: ComponentProperties[A], options?: ComponentSetOptions): this;
set(attributeName: Partial<ComponentProperties>, options?: ComponentSetOptions): this;
set<A extends string>(
attributeName: Partial<ComponentProperties> | A,
value?: SetOptions | ComponentProperties[A],
keyOrAttributes: A | Partial<ComponentProperties>,
valueOrOptions?: ComponentProperties[A] | SetOptions,
options?: ComponentSetOptions,
): this;
set<A extends string>(
attributeName: Partial<ComponentProperties> | A,
value?: SetOptions | ComponentProperties[A],
keyOrAttributes: A | Partial<ComponentProperties>,
valueOrOptions?: ComponentProperties[A] | SetOptions,
options: ComponentSetOptions = { skipWatcherUpdates: false },
): this {
const props =
typeof attributeName === 'object'
? attributeName
: typeof attributeName === 'string'
? { [attributeName as string]: value }
const attributes =
typeof keyOrAttributes === 'object'
? keyOrAttributes
: typeof keyOrAttributes === 'string'
? { [keyOrAttributes as string]: valueOrOptions }
: {};
const areStaticAttributes = DynamicValueWatcher.areStaticValues(props);
const evaluatedProps = areStaticAttributes
? props
: ComponentDynamicValueListener.evaluateComponentDef(props, this.em);
const areStaticAttributes = DynamicValueWatcher.areStaticValues(attributes);
const evaluatedAttributes = areStaticAttributes
? attributes
: ComponentDynamicValueListener.evaluateComponentDef(attributes, this.em);
if (!options.skipWatcherUpdates) {
this.componentDVListener?.watchProps(props);
this.componentDVListener?.watchProps(attributes);
}
return super.set(evaluatedProps, options);
return super.set(evaluatedAttributes, options);
}
__postAdd(opts: { recursive?: boolean } = {}) {

Loading…
Cancel
Save