Exercise: Deleting a label

In notebook:
Building Modern Web Apps
Created at:
2016-01-29
Updated:
2016-01-29
Tags:
libraries JavaScript React Ampersand
  // ****     components/label-item.js        ****
import React form 'react'
import ampersandMixin form 'ampersand-react-mixin'

export default React.createClass({
    mixins: [ampersandMixin]
    
    // ++++ 1. create the delete handler
    onDeletClick (event) {
        event.preventDefault()
        this.props.label.destroy()
    }
    
    onEditClick () { ... },
    
    onCancelClick () { ... },
    
    render () {
        const {label} = this.props
        const cssColor = '#' + label.color
        let content
        
        if (label.editing) { 
            content = (
                <form className='label'>
                    ...
                </form>
            )
        } else {
            content = (
                <div className='label'>
                    ...
                    <span className='label-color' style={{backgroundColor: cssColor}}> </span>
                    <span>{label.name}</span>
                    <span onClick={this.onEditClick}>edit label</span>
                    <span onClick={this.onCancelClick}>cancel editing</span>
                    // ++++ 2. add the delete handler
                    <span onClick={this.onDeleteClick}>delete label</span>
                </div>    
            )
        }
        return (<div>{content}</div>)
    }
})  
The UI is "optimistic", there's no {wait:true} option added, so it updates the view immediately doesn't wait for successful termination.In chrome devtools in the network tab you can check the headers. can click on the request and you get details and you see what the browser does.
If it's  a PUT or DELETE you get access-control- properties.
Talks more about REST (words, specifications)