This repository was archived by the owner on Dec 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Rex Example</ title >
7+ </ head >
8+ < body >
9+ < div id ="app-root "> </ div >
10+ < script src ="./src/index.tsx "> </ script >
11+ </ body >
12+ </ html >
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " rex-example" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "start" : " parcel index.html" ,
8+ "test" : " echo \" Error: no test specified\" && exit 1"
9+ },
10+ "keywords" : [],
11+ "author" : " " ,
12+ "license" : " ISC" ,
13+ "devDependencies" : {
14+ "parcel-bundler" : " ^1.12.4"
15+ },
16+ "dependencies" : {
17+ "@types/react" : " ^16.9.21" ,
18+ "@types/react-dom" : " ^16.9.5" ,
19+ "react" : " ^16.12.0" ,
20+ "react-dom" : " ^16.12.0"
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ import React , { useState } from "react" ;
2+ import { useRex } from "rex" ;
3+
4+ export default function App ( ) {
5+ const store = useRex ( ) ;
6+ const { todos } = store ;
7+
8+ const [ newTask , updateNewTask ] = useState ( "" ) ;
9+
10+ const onAddTask = ( ) => {
11+ todos . addTask ( newTask ) ;
12+ updateNewTask ( "" ) ;
13+ } ;
14+
15+ return (
16+ < div >
17+ < input
18+ type = "text"
19+ value = { newTask }
20+ onChange = { event => updateNewTask ( event . target . value ) }
21+ placeholder = "New Task"
22+ />
23+ < button onClick = { onAddTask } > Submit</ button >
24+ < ul >
25+ { todos . list . map ( ( item , itemIndex ) => {
26+ const onClickCheckbox = ( ) => {
27+ // now how to toggle this elegantly??
28+ } ;
29+ return (
30+ < li key = { itemIndex } >
31+ < input
32+ type = "checkbox"
33+ onChange = { onClickCheckbox }
34+ checked = { item . taskStatus }
35+ />
36+ { item . task }
37+ </ li >
38+ ) ;
39+ } ) }
40+ </ ul >
41+ </ div >
42+ ) ;
43+ }
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import ReactDOM from "react-dom" ;
3+ import { RexProvider } from "rex" ;
4+ import store from "./store/store" ;
5+ import App from "./App" ;
6+ // import './index.css'
7+
8+ ReactDOM . render (
9+ < RexProvider store = { store } >
10+ < App />
11+ </ RexProvider > ,
12+ document . getElementById ( "app-root" )
13+ ) ;
Original file line number Diff line number Diff line change 1+ import Rex from "rex" ;
2+
3+ export interface ITask {
4+ task : string ;
5+ status : boolean ;
6+ }
7+
8+ export interface ITodosRexState {
9+ list : ITask [ ] ;
10+ }
11+
12+ class Todos extends Rex {
13+ state = {
14+ list : [
15+ {
16+ task : "Task One" ,
17+ status : false
18+ } ,
19+ {
20+ task : "Task Two" ,
21+ status : false
22+ }
23+ ]
24+ } ;
25+
26+ addTask = ( newTask : string ) => {
27+ const newTaskObject = {
28+ task : newTask ,
29+ status : false
30+ } ;
31+ const list : ITask [ ] = [ ...this . state . list , newTaskObject ] ;
32+ this . setState ( { list } ) ;
33+ } ;
34+
35+ get list ( ) {
36+ return this . state . list ;
37+ }
38+ }
39+
40+ export default Todos ;
Original file line number Diff line number Diff line change 1+ import Todos from "./Todos" ;
2+
3+ const store = {
4+ todos : Todos
5+ } ;
6+
7+ export default store ;
You can’t perform that action at this time.
0 commit comments