-
-
Save bakasura980/6d2f24c2be92491ef2ef87274daf7faa to your computer and use it in GitHub Desktop.
EOSLime shape TodoApplication [ Connector ]
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
// ./index.js | |
import React from 'react'; | |
import { TodoFormHtml } from './renders/todo-form'; | |
import TodoManager from './services/todo-manager'; | |
class TodoApplication extends Component { | |
constructor() { | |
this.state = { | |
// Blockchain service | |
todoManager: null, | |
// New Todo description | |
newTodoDescription: '' | |
} | |
} | |
// React method comming from Component class | |
async componentDidMount () { | |
// Make sure methods will be visible in todo-form render | |
this.addTodo = this.addTodo.bind(this); | |
this.onNewTodoDescription = this.onNewTodoDescription.bind(this); | |
// Instantiate Blockchain service | |
const todoManager = await TodoManager.build(); | |
this.setState({ todoManager }); | |
} | |
// Visualise our "Add Todo" button | |
render () { | |
return ( | |
<div> | |
{TodoFormHtml(this)} | |
</div> | |
); | |
} | |
// Update Todo description on input box entering | |
onNewTodoDescription (event) { | |
this.setState({ newTodoDescription: event.target.value }); | |
} | |
/* | |
Once "Add Todo" button is clicked we are trigerring | |
a transaction to be broadcated in the blockchain | |
(Create Todo in the blockchain) | |
*/ | |
async addTodo () { | |
/* | |
Create a new Todo on chain by providing its description | |
By successfully broadcating a transaction you will get its | |
status and id in return | |
*/ | |
const txReceipt = await this.state.todoManager.addTodo(this.state.newTodoDescription); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment