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 Debounced = Function & { cancel(): void };
export type SetOptions = Backbone.ModelSetOptions & { export type SetOptions = Backbone.ModelSetOptions & {
unset?: boolean;
avoidStore?: boolean; avoidStore?: boolean;
avoidTransformers?: boolean; avoidTransformers?: boolean;
partial?: 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>( set<A extends string>(
attributeName: Partial<ComponentProperties> | A, keyOrAttributes: A | Partial<ComponentProperties>,
value?: SetOptions | ComponentProperties[A], valueOrOptions?: ComponentProperties[A] | SetOptions,
options?: ComponentSetOptions, options?: ComponentSetOptions,
): this; ): this;
set<A extends string>( set<A extends string>(
attributeName: Partial<ComponentProperties> | A, keyOrAttributes: A | Partial<ComponentProperties>,
value?: SetOptions | ComponentProperties[A], valueOrOptions?: ComponentProperties[A] | SetOptions,
options: ComponentSetOptions = { skipWatcherUpdates: false }, options: ComponentSetOptions = { skipWatcherUpdates: false },
): this { ): this {
const props = const attributes =
typeof attributeName === 'object' typeof keyOrAttributes === 'object'
? attributeName ? keyOrAttributes
: typeof attributeName === 'string' : typeof keyOrAttributes === 'string'
? { [attributeName as string]: value } ? { [keyOrAttributes as string]: valueOrOptions }
: {}; : {};
const areStaticAttributes = DynamicValueWatcher.areStaticValues(props);
const evaluatedProps = areStaticAttributes const areStaticAttributes = DynamicValueWatcher.areStaticValues(attributes);
? props const evaluatedAttributes = areStaticAttributes
: ComponentDynamicValueListener.evaluateComponentDef(props, this.em); ? attributes
: ComponentDynamicValueListener.evaluateComponentDef(attributes, this.em);
if (!options.skipWatcherUpdates) { 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 } = {}) { __postAdd(opts: { recursive?: boolean } = {}) {

Loading…
Cancel
Save