@@ -4,17 +4,23 @@ import { patchDOM } from "../patch-dom";
44import { DOM_TYPES , extractChildren } from "../h" ;
55import { hasOwnProperty } from "../utils/objects" ;
66
7- // A factory function that, given a render() function,
8- // creates a component class that uses that function to render its view.
97export function defineComponent ( { render, state, ...methods } ) {
108 class Component {
119 #isMounted = false ;
1210 #vdom = null ;
1311 #hostEl = null ;
12+ #eventsHandlers = null ;
13+ #parentComponent = null ;
1414
15- constructor ( props = { } ) {
15+ constructor (
16+ props = { } ,
17+ eventHandlers = { } ,
18+ parentComponent = null ,
19+ ) {
1620 this . props = props ;
1721 this . state = state ? state ( props ) : { } ;
22+ this . #eventsHandlers = eventHandlers ;
23+ this . #parentComponent = parentComponent ;
1824 }
1925
2026 get elements ( ) {
@@ -52,6 +58,13 @@ export function defineComponent({ render, state, ...methods }) {
5258 this . #patch( ) ; // To reflect the changes in the DOM
5359 }
5460
61+ updateProps ( props ) {
62+ // TODOS: By comparing the old new prop objects, we can avoid patching and
63+ // TODOS:the component—and all its subcomponents—if its props haven’t changed (deep-equal package)
64+ this . props = { ...this . props , ...props } ; // Merge new and old props.
65+ this . #patch( ) ; // Re-render
66+ }
67+
5568 render ( ) {
5669 // returns its view as a virtual DOM based on the state.
5770 return render . call ( this ) ;
0 commit comments