1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < title > React Fundamentals</ title >
6+
7+ <!-- le styles -->
8+ < link href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css " rel ="stylesheet " integrity ="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw== " crossorigin ="anonymous ">
9+ </ head >
10+
11+ < body class ="container ">
12+ < div id ="main "> </ div >
13+ </ body >
14+
15+ <!-- js -->
16+ < script src ="https://fb.me/react-0.14.7.js "> </ script >
17+ < script src ="https://fb.me/react-dom-0.14.7.js "> </ script >
18+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js "> </ script >
19+
20+ < script type ="text/babel ">
21+ /*
22+ Unidirectional Data Flow
23+
24+ Application state is managed in the top level component and flows down to the child components via props.
25+
26+ Source & Further reading:
27+ https://hashnode.com/post/why-does-react-emphasize-on-unidirectional-data-flow-and-flux-architecture-ciibz8ej600n2j3xtxgc0n1f0
28+ https://scotch.io/tutorials/learning-react-getting-started-and-concepts#unidirectional-data-flow
29+ */
30+ var FilteredList = React . createClass ( {
31+ filterList : ( event ) => {
32+ var updatedList = this . state . initialItems ;
33+ updatedList = updatedList . filter item => {
34+ return item . toLowerCase ( ) . search (
35+ event . target . value . toLowerCase ( ) ) !== - 1 ;
36+ } ) ;
37+ this . setState ( { items : updatedList } ) ;
38+ } ,
39+ getInitialState : function ( ) {
40+ return {
41+ initialItems : [
42+ 'Angular' ,
43+ 'Backbone' ,
44+ 'Ember' ,
45+ 'Express' ,
46+ 'React' ,
47+ 'Node' ,
48+ 'MongoDB' ,
49+ 'Polymer' ,
50+ 'Vue'
51+ ] ,
52+ items : [ ]
53+ }
54+ } ,
55+ componentWillMount : function ( ) {
56+ this . setState ( { items : this . state . initialItems } )
57+ } ,
58+ render : function ( ) {
59+ return (
60+ < div className = "filter-list" >
61+ < input type = "text" placeholder = "Search" onChange = { this . filterList } />
62+ < List items = { this . state . items } />
63+ </ div >
64+ )
65+ }
66+ } ) ;
67+
68+ var List = React . createClass ( {
69+ render : function ( ) {
70+ return (
71+ < ul >
72+ {
73+ this . props . items . map ( function ( item ) {
74+ return < li key = { item } > { item } </ li >
75+ } )
76+ }
77+ </ ul >
78+ )
79+ }
80+ } ) ;
81+
82+ ReactDOM . render (
83+ < FilteredList /> ,
84+ document . getElementById ( 'main' )
85+ ) ;
86+ </ script >
87+ </ html >
88+
0 commit comments