-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/vdom-inside-component: Хранение виртуального и реального DOM …
…в компоненте (#4) * feat: add common types as declaration * refactor: correct types * refactor: rename "VirtualDomNode" * feat: add common interface for virtual-dom nodes * feat: add virtual-dom component node * refactor: add any component type * refactor: move nodes in folder * feat: add support component node factory * feat: inject virtual and real dom in component * feat: add update component * fix: check base element cache
- Loading branch information
Showing
13 changed files
with
224 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import Component from '@/component'; | ||
|
||
export type ComponentConstructor = new (...unknown) => Component< | ||
Record<string, unknown>, | ||
Record<string, unknown> | ||
>; | ||
export type ComponentConstructor = new (...unknown) => AnyComponent; | ||
|
||
export type AnyComponent = Component<AnyObject, AnyObject>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type StringObject = Record<string, string>; | ||
|
||
type AnyObject = Record<string, unknown>; | ||
|
||
type EmptyObject = Record<string, never>; | ||
|
||
type isNullable<T> = T | null; | ||
|
||
type MaybeEmptyObject<T extends AnyObject> = T | EmptyObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
import { ComponentConstructor } from '@/component/types'; | ||
import VirtualDomNode from '@/virtual-dom/virtual-dom-node'; | ||
|
||
const componentFactory = ( | ||
Component: ComponentConstructor, | ||
props: Record<string, string> | ||
): VirtualDomNode => { | ||
const component = new Component(props); | ||
component.create(); | ||
|
||
const virtualDomNode = component.render(); | ||
virtualDomNode.component = component; | ||
|
||
return virtualDomNode; | ||
}; | ||
import VirtualDomComponentNode from '@/virtual-dom/nodes/virtual-dom-component-node'; | ||
import VirtualDomElementNode from '@/virtual-dom/nodes/virtual-dom-element-node'; | ||
import { VirtualDomNode, VirtualDomNodeChild } from '@/virtual-dom/types'; | ||
|
||
const elementFactory = ( | ||
tagName: string | ComponentConstructor, | ||
props: Record<string, string>, | ||
children: (VirtualDomNode | string)[] | ||
props: StringObject, | ||
children: VirtualDomNodeChild[] | ||
): VirtualDomNode => { | ||
if (typeof tagName !== 'string') { | ||
return componentFactory(tagName, props); | ||
if (typeof tagName === 'function') { | ||
return new VirtualDomComponentNode(tagName, props, children); | ||
} | ||
|
||
return new VirtualDomNode(tagName, props, children); | ||
return new VirtualDomElementNode(tagName, props, children); | ||
}; | ||
|
||
export default elementFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.