Merge pull request #58 from ecraig12345/fixes

Assorted fixes from day 2
This commit is contained in:
Elizabeth Craig 2019-03-01 13:08:11 -08:00 коммит произвёл GitHub
Родитель 111e5d6623 be6c2f2fec
Коммит 10e10f74a4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 23 добавлений и 16 удалений

Просмотреть файл

@ -50,6 +50,7 @@ body {
#markdownReadme code.hljs { #markdownReadme code.hljs {
background-color: inherit; background-color: inherit;
font-weight: bold;
} }
/** /**

Просмотреть файл

@ -30,7 +30,7 @@ Let's start off in the TodoList, as that has the most data flow up and down. The
Looking at our `TodoApp` we know that `TodoList` has three props: `filter`, `todos`, and `complete`. We'll start by creating an interface called `TodoListProps` that represents this component's props. Looking at our `TodoApp` we know that `TodoList` has three props: `filter`, `todos`, and `complete`. We'll start by creating an interface called `TodoListProps` that represents this component's props.
```tsx ```ts
interface TodoListProps { interface TodoListProps {
filter: any; filter: any;
todos: any; todos: any;
@ -42,7 +42,7 @@ interface TodoListProps {
With that interface written, we'll add it to our component class. With that interface written, we'll add it to our component class.
```tsx ```ts
export class TodoList extends React.Component<TodoListProps, any> export class TodoList extends React.Component<TodoListProps, any>
``` ```
@ -58,7 +58,7 @@ So far we've only established what our prop names are, not the type of values in
We know that `filter` shouldn't be an object, array or function, so we can specify it should always be a string like this: We know that `filter` shouldn't be an object, array or function, so we can specify it should always be a string like this:
```tsx ```ts
interface TodoListProps { interface TodoListProps {
filter: string; filter: string;
todos: any; todos: any;
@ -68,7 +68,7 @@ interface TodoListProps {
But since we know that the filter can be only one of three values, we can make that explicit with a [union type](https://www.typescriptlang.org/docs/handbook/advanced-types.html#union-types): But since we know that the filter can be only one of three values, we can make that explicit with a [union type](https://www.typescriptlang.org/docs/handbook/advanced-types.html#union-types):
```tsx ```ts
interface TodoListProps { interface TodoListProps {
filter: 'all' | 'active' | 'completed'; filter: 'all' | 'active' | 'completed';
todos: any; todos: any;
@ -82,7 +82,7 @@ Now try going back to `TodoApp` and changing the `filter` attribute in `TodoList
The `complete` prop isn't data, but a function. Fortunately, TypeScript can handle function types just as well as data. The `complete` prop isn't data, but a function. Fortunately, TypeScript can handle function types just as well as data.
```tsx ```ts
interface TodoListProps { interface TodoListProps {
filter: 'all' | 'active' | 'completed'; filter: 'all' | 'active' | 'completed';
todos: any; todos: any;
@ -98,7 +98,7 @@ For functions we are only concerned with the parameters passed in and the return
The `todos` prop is interesting in that `todos` is an object with a bunch of unknown keys. So here's what that interface would look like. The `todos` prop is interesting in that `todos` is an object with a bunch of unknown keys. So here's what that interface would look like.
```tsx ```ts
interface TodoListProps { interface TodoListProps {
filter: 'all' | 'active' | 'completed'; filter: 'all' | 'active' | 'completed';
todos: { todos: {
@ -119,7 +119,7 @@ Now that our interface is complete, try changing the word "all" in `filter === a
Most of our components will need to specify types for `todos` and `filter`, so it's a good thing that TypeScript allows us to share types between files. I've already written up and exported those shared types in the file `TodoApp.types.ts`, so we just need to import them and use them in our interface. Most of our components will need to specify types for `todos` and `filter`, so it's a good thing that TypeScript allows us to share types between files. I've already written up and exported those shared types in the file `TodoApp.types.ts`, so we just need to import them and use them in our interface.
```tsx ```ts
import { FilterTypes, Todos } from '../TodoApp.types'; import { FilterTypes, Todos } from '../TodoApp.types';
interface TodoListProps { interface TodoListProps {
@ -135,7 +135,7 @@ Our `TodoApp` doesn't take any props, but it does have state. We can use TypeScr
I've already imported `Todos` and `FilterTypes` into the `TodoApp`, so we just need to add them to our class. If we want, we can even skip a separate interface definition and just declare the type inline. (This is not recommended for types of any complexity or types that are used in multiple places.) I've already imported `Todos` and `FilterTypes` into the `TodoApp`, so we just need to add them to our class. If we want, we can even skip a separate interface definition and just declare the type inline. (This is not recommended for types of any complexity or types that are used in multiple places.)
```tsx ```ts
export class TodoApp extends React.Component<{}, { todos: Todos; filter: FilterTypes }> export class TodoApp extends React.Component<{}, { todos: Todos; filter: FilterTypes }>
``` ```
@ -145,7 +145,7 @@ export class TodoApp extends React.Component<{}, { todos: Todos; filter: FilterT
Jumping down to the TodoListItem, as we start to write the `TodoListItemProps` we realize that two of the props, `label` and `completed`, have already been defined in the `TodoItem` interface in `TodoApp.types`. So we can make `TodoListItemProps` reuse the `TodoItem` interface by extending it. Jumping down to the TodoListItem, as we start to write the `TodoListItemProps` we realize that two of the props, `label` and `completed`, have already been defined in the `TodoItem` interface in `TodoApp.types`. So we can make `TodoListItemProps` reuse the `TodoItem` interface by extending it.
```tsx ```ts
interface TodoListItemProps extends TodoItem { interface TodoListItemProps extends TodoItem {
id: string; id: string;
complete: (id: string) => void; complete: (id: string) => void;
@ -164,7 +164,7 @@ And then use the input's `onChange` event to fire our `complete` callback. We ca
> A [callback function](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function) is a function passed into a component as a prop. > A [callback function](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function) is a function passed into a component as a prop.
```tsx ```jsx
<input type="checkbox" checked={completed} onChange={() => complete(id)} /> <input type="checkbox" checked={completed} onChange={() => complete(id)} />
``` ```

Просмотреть файл

@ -50,6 +50,12 @@ function makePromise() {
return Promise.resolve(5); return Promise.resolve(5);
} }
// TODO: call makePromise() using await syntax and log the results
// TODO: create a new async function // TODO: create a new async function
async function run() {
// TODO: call makePromise() using await syntax and log the results
// TODO: call your new async function
}
run();

Просмотреть файл

@ -21,7 +21,7 @@ There are some predefined themes within Fabric already, like Fluent (which will
The following code (simplified from `demo/src/components/TodoApp.tsx`) shows an example of applying the Fluent theme to our todo app using `Customizer`. The following code (simplified from `demo/src/components/TodoApp.tsx`) shows an example of applying the Fluent theme to our todo app using `Customizer`.
```js ```jsx
import { Customizer } from 'office-ui-fabric-react'; import { Customizer } from 'office-ui-fabric-react';
import { FluentCustomizations } from '@uifabric/fluent-theme'; import { FluentCustomizations } from '@uifabric/fluent-theme';
@ -128,7 +128,7 @@ Benefits of `mergeStyles` include:
The following is a basic example using mergeStyles. ([This CodePen](https://codepen.io/dzearing/pen/jGdgrE?editors=1011) illustrates in more detail what `mergeStyles` does and includes some advanced examples.) The following is a basic example using mergeStyles. ([This CodePen](https://codepen.io/dzearing/pen/jGdgrE?editors=1011) illustrates in more detail what `mergeStyles` does and includes some advanced examples.)
```js ```jsx
// can also import from office-ui-fabric-react in Fabric-based apps // can also import from office-ui-fabric-react in Fabric-based apps
import { mergeStyles } from '@uifabric/merge-styles'; import { mergeStyles } from '@uifabric/merge-styles';

Просмотреть файл

@ -46,7 +46,7 @@ import { TeamsCustomizations } from '@uifabric/theme-samples';
1. Try generating a class name using `mergeStyles` and use it as a `className` prop inside `TodoApp` 1. Try generating a class name using `mergeStyles` and use it as a `className` prop inside `TodoApp`
```tsx ```jsx
import { mergeStyles } from 'office-ui-fabric-react'; import { mergeStyles } from 'office-ui-fabric-react';
const className = mergeStyles({ const className = mergeStyles({

Просмотреть файл

@ -42,7 +42,7 @@ In a real app using ReactDOM, the top-level component will be rendered on the pa
The following code demonstrates how Enzyme can be used to help test React components. The following code demonstrates how Enzyme can be used to help test React components.
```tsx ```jsx
import React from 'react'; import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import { TestMe } from './TestMe'; import { TestMe } from './TestMe';