This file contains hidden or 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 hidden or 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
type AAndB = { | |
a: string; | |
b: string; | |
}; | |
type Neither = { | |
someOtherProp: string; | |
}; | |
type Props = AAndB | Neither; |
This file contains hidden or 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
var todos = [] | |
function addTodo(task) { | |
todos.push({ | |
task: task, | |
completed: false, | |
}); | |
} | |
addTodo("Feed my cat"); |
This file contains hidden or 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
it("can add an alert", () => { | |
const TestComponent = () => { | |
return ( | |
<AlertProvider> | |
<Layout> | |
<ComponentWithAlert /> | |
</Layout> | |
</AlertProvider> | |
); | |
}; |
This file contains hidden or 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 Layout extends React.Component { | |
render() { | |
return ( | |
<AlertContext.Consumerr> | |
{({ alert }) => ( | |
<React.Fragment> | |
{alert && <FancyAlertMessage alert={alert} /> | |
{this.props.children} | |
</React.Fragment> | |
)} |
This file contains hidden or 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 AlertContext = React.createContext<IAlertContext>({ | |
alert: undefined, | |
showAlert: (alert) => {}, | |
}); | |
// Here we are creating a context with default values | |
class AlertProvider extends React.Component { | |
state = { | |
alert: undefined | |
}; |
This file contains hidden or 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
<AlertProvider> // This context provides a way to display alerts and access alerts | |
<Layout> // This layout container can access the alert to display in the header | |
<Router> | |
<Route exact path="/" component={Home} /> // This route can create an alert to show in the layout | |
</Router> | |
</Layout> | |
</AlertProvider> |
This file contains hidden or 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
<AlertProvider> // This context provides a way to display alerts and access alerts | |
<Layout> // This layout container can access the alert to display in the header | |
<Router> | |
<Route exact path="/" component={Home} /> // This route can create an alert to show in the layout | |
</Router> | |
</Layout> | |
</Router> |
This file contains hidden or 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 SimpleComponentWithAlert extends React.Component { | |
render() { | |
const myAlert = { message: "This is my alert", type: "error" }; | |
return ( | |
<AlertManager> | |
{({ alert, showAlert }) => ( | |
<div> | |
{alert && <FancyAlertMessage alert={alert} />} | |
<button onClick={() => showAlert(myAlert)}>Show Alert</button> | |
</div> |
This file contains hidden or 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 AlertManager extends React.Component { | |
state = { | |
alert: undefined | |
}; | |
render() { | |
const { alert } = this.state; | |
const { children } = this.props; | |
return children({ alert, showAlert: this.showAlert }); | |
} |
NewerOlder