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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
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
interface User { | |
fullName(): string; | |
adult(): boolean; | |
} | |
class Citizen implements User { | |
constructor(private firstName: string, private lastName: string, private age: number) { | |
} | |
fullName() { |
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
# fetch articles for user with ID "myUserId" | |
curl --verbose -X GET "http://localhost:4000/users/myUserId/articles" | |
# response: | |
# [{"title":"qui vero quo enim error","content":"...","createdAt":"2018-04-26T05:50:26.130Z"}, ...] | |
# try to register user with valid user name | |
curl --verbose -X POST http://localhost:4000/register -H 'content-type: application/json' -d '{"userName":"valid"}' | |
# response: | |
# ... | |
# < HTTP/1.1 200 OK |
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
server.get("/users/:id/articles", (request, response) => { | |
const delay = faker.random.number({min: 400, max: 1000}); | |
// delay response with fake articles | |
setTimeout(() => { | |
response.send(200, getArticlesForUser()); | |
}, delay); | |
}); |
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
const faker = require("faker"); | |
server.get("/users/:id/articles", (request, response) => { | |
response.send(200, getArticlesForUser()); | |
}); | |
// you can create articles on the fly | |
// or prepare few articles upfront | |
// and just select them now | |
function getArticlesForUser() { |
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
server.post("/register", (request, response) => { | |
const userName = request.body.userName; | |
// we can use request data to trigger positive | |
// or negative response, whatever we need | |
if (userName === "invalid") { | |
response.send(400, { | |
message: "Invalid user name." | |
}); | |
} else { |
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
const restify = require("restify"); | |
// create server instance | |
const server = restify.createServer(); | |
// use plugins to parse body and query string of incoming requests | |
server.use(restify.plugins.queryParser()); | |
server.use(restify.plugins.bodyParser()); | |
// start listening |
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
/* | |
import {connect} from "react-redux"; | |
import * as actions from "./actions"; | |
import LoginForm from "./components/LoginForm"; | |
*/ | |
export class Login extends Component { | |
render() { | |
return ( |
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
class Button extends React.Component { | |
render() { | |
return <button style={{background: this.context.color}}> {this.props.children}</button>; | |
} | |
} | |
Button.contextTypes = { | |
color: React.PropTypes.string | |
}; |
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
class MyComponent extends Component { | |
render() { | |
return <input ref={(element) => this._input = element} />; | |
} | |
componentDidMount() { | |
this._input.focus(); | |
} | |
NewerOlder