Skip to content

Commit

Permalink
* core: refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Jul 19, 2024
1 parent cffadac commit dc3a1fa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/core/src/react/component-from-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {createRef, render, h} from 'preact';
import {Component as ComponentBase} from '../component';
import {mergeProps} from '../helpers';

import type {ComponentEventsDefnition} from '../component';
import type {Component as ComponentReact, ComponentClass} from 'preact';
import {I18nLangMap} from '../i18n';
import {type I18nLangMap} from '../i18n';
import type {ComponentEventsDefnition} from '../component';

export class ComponentFromReact<O extends {} = {}, C extends ComponentReact<O> = ComponentReact<O>, E extends ComponentEventsDefnition = {}, U extends HTMLElement = HTMLElement> extends ComponentBase<O & {$replace?: boolean}, E, U> {
/**
Expand Down Expand Up @@ -71,16 +71,17 @@ export class ComponentFromReact<O extends {} = {}, C extends ComponentReact<O> =
* @param options new options.
*/
render(options?: Partial<O>, reset?: boolean) {
const {element} = this;
const {element, $: instance} = this;
const {Component, replace} = this.constructor;
const {$replace = replace, $optionsFromDataset, ...userOptions} = this.setOptions(options, reset);
const props = {
ref: this._ref,
...userOptions,
};
if (reset) {
(this.$ as {resetState?: (props?: Record<string, unknown>, init?: boolean) => void})?.resetState?.(userOptions);
(instance as {resetState?: (props?: Record<string, unknown>, init?: boolean) => void})?.resetState?.(userOptions);
}

if ($replace && (Component as {HElement?: boolean}).HElement && (element.tagName.toLowerCase() === $replace || $replace === true)) {
const attrs = Array.from(element.attributes).reduce<Record<string, unknown>>((data, attribute) => {
const {name, value} = attribute;
Expand Down

0 comments on commit dc3a1fa

Please sign in to comment.