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 quickSort = ( | |
| unsortedArray, | |
| comparator = defaultComparator | |
| ) => { | |
| // Create a sortable array to return. | |
| const sortedArray = [...unsortedArray]; | |
| // Recursively sort sub-arrays. | |
| const recursiveSort = (start, end) => { |
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 defaultComparator = (a, b) => { | |
| if (a < b) { | |
| return -1; | |
| } | |
| if (a > b) { | |
| return 1; | |
| } | |
| return 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
| const quickSort = (unsortedArray) => { | |
| const sortedArray = TODO(unsortedArray); | |
| return sortedArray; | |
| }; |
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
| // NEW: lifespan parameter | |
| const useFetch = ( | |
| input: RequestInfo, | |
| init?: RequestInit | undefined, | |
| lifespan: number = 0 | |
| ) => { | |
| // ... | |
| const fetchCache: FetchCache = { |
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 deepEqual = require('deep-equal'); | |
| interface FetchCache { | |
| fetch?: Promise<void>; | |
| error?: any; | |
| init: RequestInit | undefined; | |
| input: RequestInfo; | |
| response?: any; | |
| } |
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
| import useFetch from 'fetch-suspense'; | |
| const MyComponent = () => { | |
| // "Look! In the example! It's a fetch() request! It's a hook!" | |
| // "No! It's kind of like both at the same time." | |
| const serverResponse = useFetch('/path/to/api', { method: 'POST' }); | |
| // The return value is the body of the server's response. | |
| return <div>{serverResponse}</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 Suspense extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| promise: null | |
| }; | |
| } | |
| componentDidCatch(e) { |
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 Suspense extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| error: null | |
| }; | |
| } | |
| componentDidCatch(e) { |
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
| import React, { Component } from 'reactn'; | |
| import './App.css'; | |
| class App extends Component { | |
| componentDidMount() { | |
| this.setGlobal( | |
| fetch('index.html') | |
| .then(response => response.text()) | |
| .then(html => ({ |
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
| import React from 'react'; | |
| import { setGlobal } from 'reactn'; | |
| import ReactDOM from 'react-dom'; | |
| import App from './App'; | |
| setGlobal({ | |
| data: null, | |
| x: 0 | |
| }); |