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 React from "react" | |
import { addPost } from "./api" | |
function Posts() { | |
const [posts, addLocalPost] = React.useReducer((s, a) => [...s, a], []) | |
const [formData, setFormData] = React.useReducer((s, a) => ({ ...s, ...a }), { | |
title: "", | |
content: "", | |
}) |
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 React from "react"; | |
function Todos({ todos: originalTodos }) { | |
const filters = ["all", "active", "done"]; | |
const [input, setInput] = React.useState(""); | |
const [todos, setTodos] = React.useState(originalTodos || []); | |
const [activeFilter, setActiveFilter] = React.useState(filters[0]); | |
const addTodo = (e) => { | |
if (e.key === "Enter" && input.length > 0) { |
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 React from "react"; | |
import { shallow } from "enzyme"; | |
import Counter from "./counter"; | |
describe("<Counter />", () => { | |
it("properly increments and decrements the counter", () => { | |
const wrapper = shallow(<Counter />); | |
expect(wrapper.state("count")).toBe(0); |
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
<template> | |
<label class="container"> | |
<input | |
v-bind="$attrs" | |
class="input" | |
type="checkbox" | |
:checked="checked" | |
@change="$emit('update:checked', $event.target.checked)" | |
/> | |
<span class="switch"></span> |
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
// agent is an instance of WebhookClient | |
function setContextData(agent) { | |
const handler = { | |
set(target, property, value) { | |
const parameters = agent.context.get("data") | |
? agent.context.get("data").parameters | |
: {}; | |
parameters[property] = value; |
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 Stack { | |
constructor (capacity) { | |
this.items = [] | |
this.capacity = capacity | |
} | |
isEmpty () { | |
return this.items.length === 0 | |
} |