11import React , { PureComponent } from 'react' ;
22import { Intro , InputPrerequisites } from './components' ;
33import * as Forms from './forms' ;
4+ import { bindState } from '../../src' ;
45
56const sections = [
67 'inputs' , 'form01' , 'form02' , 'form03' , 'form04' ,
78 'form05' , 'form06' , 'form07' , 'form08' , 'form09' , 'form10'
89] . reverse ( ) ;
910
1011export default class App extends PureComponent {
11- state = { forms : { } , section : 'inputs' } ;
12+ state = { section : 'inputs' } ;
1213
1314 componentDidMount ( ) {
1415 window . addEventListener ( 'scroll' , this . setActiveSection ) ;
@@ -30,17 +31,6 @@ export default class App extends PureComponent {
3031 return this . state . section === section ? 'active' : '' ;
3132 }
3233
33- formProps ( name ) {
34- const props = this . state . forms [ name ] || { } ;
35-
36- return {
37- attrs : props . attrs || { } ,
38- onChange : ( attrs , errors ) => this . setState ( {
39- forms : { ...this . state . forms , [ name ] : { attrs, errors } }
40- } )
41- } ;
42- }
43-
4434 saveForm11 = ( attrs , form ) => {
4535 // simulated AJAX request
4636 return new Promise ( ( resolve , reject ) => {
@@ -77,17 +67,17 @@ export default class App extends PureComponent {
7767 < div className = "content paper flex-item p-20" >
7868 < Intro />
7969 < div id = "inputs" > < InputPrerequisites /> </ div >
80- < div id = "form01" > < Forms . Form1 { ...this . formProps ( 'form1' ) } /> </ div >
81- < div id = "form02" > < Forms . Form2 { ...this . formProps ( 'form2' ) } /> </ div >
82- < div id = "form03" > < Forms . Form3 { ...this . formProps ( 'form3' ) } /> </ div >
83- < div id = "form04" > < Forms . Form4 { ...this . formProps ( 'form4' ) } /> </ div >
84- < div id = "form05" > < Forms . Form5 { ...this . formProps ( 'form5' ) } /> </ div >
85- < div id = "form06" > < Forms . Form6 { ...this . formProps ( 'form6' ) } /> </ div >
86- < div id = "form07" > < Forms . Form7 { ...this . formProps ( 'form7' ) } /> </ div >
87- < div id = "form08" > < Forms . Form8 { ...this . formProps ( 'form8' ) } /> </ div >
88- < div id = "form09" > < Forms . Form9 { ...this . formProps ( 'form9' ) } /> </ div >
89- < div id = "form10" > < Forms . Form10 { ...this . formProps ( 'form10' ) } /> </ div >
90- < div id = "form11" > < Forms . Form11 { ...this . formProps ( 'form11' ) } onRequestSave = { this . saveForm11 } /> </ div >
70+ < div id = "form01" > < Forms . Form1 { ...bindState ( this , 'form1' ) } /> </ div >
71+ < div id = "form02" > < Forms . Form2 { ...bindState ( this , 'form2' ) } /> </ div >
72+ < div id = "form03" > < Forms . Form3 { ...bindState ( this , 'form3' ) } /> </ div >
73+ < div id = "form04" > < Forms . Form4 { ...bindState ( this , 'form4' ) } /> </ div >
74+ < div id = "form05" > < Forms . Form5 { ...bindState ( this , 'form5' ) } /> </ div >
75+ < div id = "form06" > < Forms . Form6 { ...bindState ( this , 'form6' ) } /> </ div >
76+ < div id = "form07" > < Forms . Form7 { ...bindState ( this , 'form7' ) } /> </ div >
77+ < div id = "form08" > < Forms . Form8 { ...bindState ( this , 'form8' ) } /> </ div >
78+ < div id = "form09" > < Forms . Form9 { ...bindState ( this , 'form9' ) } /> </ div >
79+ < div id = "form10" > < Forms . Form10 { ...bindState ( this , 'form10' ) } /> </ div >
80+ < div id = "form11" > < Forms . Form11 { ...bindState ( this , 'form11' ) } onRequestSave = { this . saveForm11 } /> </ div >
9181 </ div >
9282 </ div >
9383 </ div >
0 commit comments