1- import React from "react" ;
2- import "./App.css" ;
3- import ErrorMessage from "./components/ErrorMessage" ;
4- import { useAgile } from "@agile-ts/react" ;
5- import { signUpEditor } from "./core/signUpEditor" ;
6- import { generateColor , generateId } from "./core/utils" ;
1+ import React from 'react' ;
2+ import './App.css' ;
3+ import ErrorMessage from './components/ErrorMessage' ;
4+ import { useAgile } from '@agile-ts/react' ;
5+ import { signUpEditor } from './core/signUpEditor' ;
6+ import { generateColor , generateId } from './core/utils' ;
7+
8+ let renderCount = 0 ;
79
810const App = ( ) => {
911 useAgile ( signUpEditor . deps ) ;
1012
13+ renderCount ++ ;
14+
1115 return (
1216 < form >
1317 < h1 > Sign Up</ h1 >
1418 < label > First Name:</ label >
1519 < input
16- onChange = { ( e ) => signUpEditor . setValue ( " firstName" , e . target . value ) }
17- value = { signUpEditor . getValueById ( " firstName" ) }
20+ onChange = { ( e ) => signUpEditor . setValue ( ' firstName' , e . target . value ) }
21+ defaultValue = { signUpEditor . getItemInitialValue ( ' firstName' ) }
1822 />
19- < ErrorMessage error = { signUpEditor . getStatus ( " firstName" ) ?. message } />
23+ < ErrorMessage error = { signUpEditor . getStatus ( ' firstName' ) ?. message } />
2024
2125 < label > Last Name:</ label >
2226 < input
2327 onChange = { ( e ) =>
24- signUpEditor . setValue ( " lastName" , e . target . value , {
28+ signUpEditor . setValue ( ' lastName' , e . target . value , {
2529 background : false ,
2630 } )
2731 }
28- value = { signUpEditor . getValueById ( "lastName" ) }
32+ defaultValue = { signUpEditor . getItemInitialValue ( 'lastName' ) }
33+ value = { signUpEditor . getItemValue ( 'lastName' ) }
2934 />
30- < ErrorMessage error = { signUpEditor . getStatus ( " lastName" ) ?. message } />
35+ < ErrorMessage error = { signUpEditor . getStatus ( ' lastName' ) ?. message } />
3136
3237 < label > Image</ label >
3338 < div
34- style = { { display : "flex" , flexDirection : "row" , alignItems : "center" } }
35- >
39+ style = { { display : 'flex' , flexDirection : 'row' , alignItems : 'center' } } >
3640 < div
3741 style = { {
38- backgroundColor : signUpEditor . getValueById ( " image" ) ?. color ,
42+ backgroundColor : signUpEditor . getItemValue ( ' image' ) ?. color ,
3943 width : 100 ,
4044 height : 100 ,
4145 borderRadius : 100 ,
@@ -45,64 +49,73 @@ const App = () => {
4549 style = { { marginLeft : 50 } }
4650 onClick = { ( event ) => {
4751 signUpEditor . setValue (
48- " image" ,
52+ ' image' ,
4953 {
5054 id : generateId ( ) ,
5155 color : generateColor ( ) ,
5256 } ,
5357 { background : false }
5458 ) ;
5559 event . preventDefault ( ) ;
56- } }
57- >
60+ } } >
5861 Reset Image
5962 </ button >
6063 </ div >
61- < ErrorMessage error = { signUpEditor . getStatus ( " image" ) ?. message } />
64+ < ErrorMessage error = { signUpEditor . getStatus ( ' image' ) ?. message } />
6265
6366 < label > Gender</ label >
6467 < select
65- defaultValue = { "" }
66- onChange = { ( e ) => signUpEditor . setValue ( "gender" , e . target . value ) }
67- >
68- < option value = { "" } > Select...</ option >
68+ defaultValue = { '' }
69+ onChange = { ( e ) => signUpEditor . setValue ( 'gender' , e . target . value ) } >
70+ < option value = { '' } > Select...</ option >
6971 < option value = "male" > Male</ option >
7072 < option value = "female" > Female</ option >
7173 </ select >
72- < ErrorMessage error = { signUpEditor . getStatus ( " gender" ) ?. message } />
74+ < ErrorMessage error = { signUpEditor . getStatus ( ' gender' ) ?. message } />
7375
7476 < label > Username</ label >
7577 < input
76- onChange = { ( e ) => signUpEditor . setValue ( "userName" , e . target . value ) }
78+ onChange = { ( e ) => signUpEditor . setValue ( 'userName' , e . target . value ) }
79+ defaultValue = { signUpEditor . getItemInitialValue ( 'userName' ) }
7780 />
78- < ErrorMessage error = { signUpEditor . getStatus ( " userName" ) ?. message } />
81+ < ErrorMessage error = { signUpEditor . getStatus ( ' userName' ) ?. message } />
7982
8083 < label > Email</ label >
81- < input onChange = { ( e ) => signUpEditor . setValue ( "email" , e . target . value ) } />
82- < ErrorMessage error = { signUpEditor . getStatus ( "email" ) ?. message } />
84+ < input
85+ onChange = { ( e ) => signUpEditor . setValue ( 'email' , e . target . value ) }
86+ defaultValue = { signUpEditor . getItemInitialValue ( 'email' ) }
87+ />
88+ < ErrorMessage error = { signUpEditor . getStatus ( 'email' ) ?. message } />
8389
8490 < label > Age</ label >
85- < input onChange = { ( e ) => signUpEditor . setValue ( "age" , e . target . value ) } />
86- < ErrorMessage error = { signUpEditor . getStatus ( "age" ) ?. message } />
91+ < input
92+ onChange = { ( e ) =>
93+ signUpEditor . setValue ( 'age' , e . target . value , { background : false } )
94+ }
95+ defaultValue = { signUpEditor . getItemInitialValue ( 'age' ) }
96+ value = { signUpEditor . getItemValue ( 'age' ) }
97+ />
98+ < ErrorMessage error = { signUpEditor . getStatus ( 'age' ) ?. message } />
8799
88100 < label > About you</ label >
89101 < textarea
90- onChange = { ( e ) => signUpEditor . setValue ( "aboutYou" , e . target . value ) }
102+ onChange = { ( e ) => signUpEditor . setValue ( 'aboutYou' , e . target . value ) }
103+ defaultValue = { signUpEditor . getItemInitialValue ( 'aboutYou' ) }
91104 />
92- < ErrorMessage error = { signUpEditor . getStatus ( " aboutYou" ) ?. message } />
105+ < ErrorMessage error = { signUpEditor . getStatus ( ' aboutYou' ) ?. message } />
93106
94107 < button
95108 style = { { marginLeft : 50 } }
96109 onClick = { async ( event ) => {
97110 event . preventDefault ( ) ;
98111 console . log ( signUpEditor ) ;
99112 await signUpEditor . submit ( ) ;
100- } }
101- >
113+ } } >
102114 Submit
103115 </ button >
104116 < p > Is Modified: { signUpEditor . isModified . toString ( ) } </ p >
105117 < p > Is Valid: { signUpEditor . isValid . toString ( ) } </ p >
118+ < p > Render Count: { renderCount } </ p >
106119 </ form >
107120 ) ;
108121} ;
0 commit comments