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
| // List.js | |
| import AddItem from "./AddItem"; | |
| const List = (props) => { | |
| const { items } = props; | |
| console.log("List rendered: ", props.listKey); | |
| return ( |
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
| // AddItem.js | |
| import { useState } from "react"; | |
| const AddItem = (props) => { | |
| const [item, setItem] = useState(""); | |
| const onChange = (e) => { | |
| setItem(e.target.value); | |
| }; |
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
| // App.js | |
| import { useState } from "react"; | |
| import List from "./List"; | |
| import "./styles.css"; | |
| function App() { | |
| const [books, setBooks] = useState([]); | |
| const [courses, setCourses] = useState([]); |
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 items: (Item | undefined)[] // Wait whaaat |
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
| // Our type-guard | |
| const isItem = (item: Item | undefined): item is Item => { | |
| return typeof item !== "undefined" | |
| } | |
| const items = itemIds.map(getItems).filter(isItem); //items: Item[] |
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 processItem = (item: Item) => { | |
| return { | |
| ...item, | |
| name: item.name.toUpperCase() | |
| } | |
| } | |
| const processedItems = items.map(item => { | |
| // Argument of type 'Item | undefined' is not assignable | |
| // to parameter of type 'Item' |
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 items = itemIds.map(getItems).filter(item => !!item); | |
| console.log(items) // No undefined values in items |
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
| interface Item { | |
| id: string; | |
| name: string; | |
| description: string; | |
| } | |
| const myItems: Array<Item> = [ | |
| { id: "1", name: "item-1", description: "bla bla bla" }, | |
| { id: "2", name: "item-2", description: "yada yada yada" }, | |
| { id: "3", name: "item-3", description: "bla bla bla" }, |
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
| name: Lint | |
| on: [push] | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Setup Node.js environment | |
| uses: actions/setup-node@v2.4.0 |
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
| def request_handler(request): | |
| global model | |
| if model is None: | |
| download_model(bucket_name='YOUR_BUCKET_NAME', | |
| source_dir='MODEL_SOURCE_DIR', | |
| destination_folder = 'DESTINATION_TO_DOWNLOAD_MODEL', | |
| model_version='MODEL_VERSION') | |
| model = tf.keras.models.load_model('DESTINATION_FOLDER') |
NewerOlder