-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ericpoon/develop
Merge develop into master
- Loading branch information
Showing
33 changed files
with
1,923 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"presets": ["env"], | ||
"presets": ["env", "react"], | ||
"plugins": ["transform-decorators-legacy", "transform-class-properties"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/node_modules | ||
/.idea | ||
/dist | ||
/coverage | ||
*.log | ||
examples/public/bundle.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Counter</title> | ||
</head> | ||
<body> | ||
<div id="counter-app"></div> | ||
<script type="text/javascript" src="../public/bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { Component } from 'react'; | ||
import ReactDom from 'react-dom'; | ||
import { observable, observer } from '../../src/core/index'; | ||
|
||
@observer | ||
class Main extends Component { | ||
render() { | ||
const { counter } = this.props; | ||
|
||
return ( | ||
<p>Count: {counter.count}</p> | ||
); | ||
} | ||
} | ||
|
||
class Counter { | ||
@observable | ||
count = 0; | ||
} | ||
|
||
const counter = new Counter(); | ||
|
||
setInterval(() => { | ||
counter.count += 1; | ||
}, 300); | ||
|
||
const app = document.getElementById('counter-app'); | ||
if (app) ReactDom.render(<Main counter={counter} />, app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Demo | ||
|
||
#### How to start | ||
|
||
1) Go back to the project root directory | ||
2) `yarn install` | ||
3) `yarn start:demo` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Todo List</title> | ||
</head> | ||
<body> | ||
<div id="todo-list-app"></div> | ||
<script type="text/javascript" src="../public/bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { Component } from 'react'; | ||
import ReactDom from 'react-dom'; | ||
import { observer } from '../../src/core'; | ||
import Task from './models/Task'; | ||
import TaskList from './models/TaskList'; | ||
|
||
@observer | ||
class Main extends Component { | ||
taskItem = (task) => { | ||
const { title, done } = task; | ||
const onTaskClick = () => task.done = !task.done; | ||
return ( | ||
<div> | ||
<label style={{ color: done ? 'green' : 'red', fontSize: 20, lineHeight: 2 }}> | ||
<input type={'checkbox'} checked={done} onClick={onTaskClick} /> | ||
{title} | ||
</label> | ||
</div> | ||
); | ||
}; | ||
|
||
render() { | ||
const { tasks } = this.props; | ||
const { finished, unfinished } = tasks; | ||
|
||
return ( | ||
<div> | ||
<h2>Task List</h2> | ||
<p>Summary: {finished.length} completed and {unfinished.length} to be done.</p> | ||
{tasks.list.map(task => { | ||
return <div key={task.title}>{this.taskItem(task)}</div>; | ||
})} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const tasks = new TaskList(); | ||
const taskA = new Task('Pick up laundry', false); | ||
const taskB = new Task('Go to supermarket', false); | ||
const taskC = new Task('Take medicine', false); | ||
const taskD = new Task('Housekeeping', false); | ||
const taskE = new Task('Appointment with clients', false); | ||
|
||
tasks.list.push(taskA); | ||
tasks.list.push(taskB); | ||
tasks.list.push(taskC); | ||
tasks.list.push(taskD); | ||
tasks.list.push(taskE); | ||
|
||
const app = document.getElementById('todo-list-app'); | ||
if (app) ReactDom.render(<Main tasks={tasks} />, app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { observable } from '../../../src/core'; | ||
|
||
export default class Task { | ||
constructor(t, d) { | ||
this.title = t; | ||
this.done = d; | ||
} | ||
|
||
@observable done; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default class TaskList { | ||
list = []; | ||
|
||
get finished() { | ||
return this.list.filter(i => i.done); | ||
} | ||
|
||
get unfinished() { | ||
return this.list.filter(i => !i.done); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { Component } from 'react'; | ||
import { observer } from '../../../src/core'; | ||
|
||
@observer | ||
class TaskInput extends Component { | ||
render() { | ||
const { label, buttonText, task, onSubmit } = this.props; | ||
return ( | ||
<div> | ||
{label} | ||
<input | ||
type={'text'} | ||
value={task.title} | ||
onChange={event => { | ||
task.title = event.target.value; | ||
}} | ||
/> | ||
<button onClick={onSubmit}>{buttonText}</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default TaskInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
|
||
const TaskItem = ({ task, onEditClick, onDeleteClick }) => { | ||
const { title, done } = task; | ||
const onTaskClick = () => { | ||
task.done = !task.done; | ||
}; | ||
|
||
return ( | ||
<div> | ||
<label style={{ color: done ? 'green' : 'red', fontSize: 20, lineHeight: 2 }}> | ||
<input type={'checkbox'} checked={done} onChange={onTaskClick} /> | ||
{title} | ||
</label> | ||
<button onClick={onEditClick}>Edit</button> | ||
<button onClick={onDeleteClick}>Delete</button> | ||
<hr /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TaskItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { Component } from 'react'; | ||
import { observer } from '../../../src/core'; | ||
import TaskItemComponent from './TaskItem'; | ||
import TaskInput from './TaskInput'; | ||
import Task from '../models/Task'; | ||
|
||
@observer | ||
class TaskList extends Component { | ||
state = { | ||
editingIdx: -1, | ||
}; | ||
|
||
observableTask = new Task(); | ||
|
||
onTaskEditClick = (task, idx) => { | ||
this.observableTask.title = task.title; | ||
this.setState({ editingIdx: idx }); | ||
}; | ||
|
||
onTaskDeleteClick = (idx) => { | ||
if (idx === this.state.editingIdx) { | ||
this.setState({ editingIdx: -1 }); | ||
this.observableTask.title = ''; | ||
} | ||
this.props.tasks.list.remove(idx); | ||
}; | ||
|
||
renderInputComponent = () => { | ||
const { editingIdx } = this.state; | ||
const { list } = this.props.tasks; | ||
const isEditing = editingIdx >= 0; | ||
let label, buttonText, onSubmit; | ||
|
||
if (isEditing) { | ||
label = 'Edit task: '; | ||
buttonText = 'Save'; | ||
onSubmit = () => { | ||
list[editingIdx].title = this.observableTask.title; | ||
this.setState({ editingIdx: -1 }); | ||
this.observableTask.title = ''; | ||
}; | ||
} else { | ||
label = 'New task: '; | ||
buttonText = 'Add'; | ||
onSubmit = () => { | ||
list.push(new Task(this.observableTask.title, false)); | ||
this.observableTask.title = ''; | ||
}; | ||
} | ||
|
||
return ( | ||
<TaskInput | ||
label={label} | ||
buttonText={buttonText} | ||
task={this.observableTask} | ||
onSubmit={onSubmit} | ||
/> | ||
); | ||
}; | ||
|
||
renderTaskItems = () => { | ||
const list = [...this.props.tasks.list]; // safe copy to avoid index issue due to deletion | ||
return list.map((task, idx) => { | ||
return ( | ||
<div key={task.title}> | ||
<TaskItemComponent | ||
task={task} | ||
onEditClick={() => this.onTaskEditClick(task, idx)} | ||
onDeleteClick={() => this.onTaskDeleteClick(idx)} | ||
/> | ||
</div> | ||
); | ||
}); | ||
}; | ||
|
||
render() { | ||
const { finished, unfinished } = this.props.tasks; | ||
|
||
return ( | ||
<div> | ||
<h2>Task List (Advanced)</h2> | ||
<p>Summary: {finished.length} completed and {unfinished.length} to be done.</p> | ||
{this.renderTaskItems()} | ||
{this.renderInputComponent()} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default TaskList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Todo List (Advanced)</title> | ||
</head> | ||
<body> | ||
<div id="todo-list-advanced-app"></div> | ||
<script type="text/javascript" src="../public/bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import ReactDom from 'react-dom'; | ||
import Task from './models/Task'; | ||
import TaskList from './models/TaskList'; | ||
import TaskListComponent from './components/TaskList'; | ||
|
||
const tasks = new TaskList(); | ||
const taskA = new Task('Pick up laundry', true); | ||
const taskB = new Task('Go to supermarket', true); | ||
const taskC = new Task('Take medicine', false); | ||
const taskD = new Task('Housekeeping', false); | ||
const taskE = new Task('Appointment with clients', false); | ||
|
||
tasks.list.push(taskA); | ||
tasks.list.push(taskB); | ||
tasks.list.push(taskC); | ||
tasks.list.push(taskD); | ||
tasks.list.push(taskE); | ||
|
||
const app = document.getElementById('todo-list-advanced-app'); | ||
if (app) ReactDom.render(<TaskListComponent tasks={tasks} />, app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { observable } from '../../../src/core'; | ||
|
||
export default class Task { | ||
constructor(t, d) { | ||
this.title = t; | ||
this.done = d; | ||
} | ||
|
||
@observable title; | ||
@observable done; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { observable } from '../../../src/core'; | ||
|
||
export default class TaskList { | ||
@observable list = []; | ||
|
||
get finished() { | ||
return this.list.filter(i => i.done); | ||
} | ||
|
||
get unfinished() { | ||
return this.list.filter(i => !i.done); | ||
} | ||
} |
Oops, something went wrong.