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
| describe('Article resource', () => { | |
| test('getArticles returns a list of articles', async () => { | |
| // Set up the mock request | |
| const scope = nock('https://dev.to/api/') | |
| .get('/articles') | |
| .reply(200, [{ title: 'Article' }]) | |
| // Make the request | |
| const DevToClient = new DevTo({ apiKey: 'XYZ' }) | |
| await DevToClient.getArticles() | |
| // Assert that the expected request was made. |
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
| function request<T> (endpoint: string, options?: RequestInit): Promise<T> { | |
| const url = this.basePath + endpoint | |
| const headers = { | |
| 'api-key': this.apiKey, | |
| 'Content-type': 'application/json' | |
| } | |
| const config = { | |
| ...options, | |
| headers, | |
| } |
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
| function applyMixins(derivedCtor: any, baseCtors: any[]) { | |
| baseCtors.forEach(baseCtor => { | |
| Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { | |
| Object.defineProperty( | |
| derivedCtor.prototype, | |
| name, | |
| Object.getOwnPropertyDescriptor(baseCtor.prototype, name) | |
| ); | |
| }); | |
| }); |
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
| <!DOCTYPE html> | |
| <html dir="ltr" lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0"> | |
| <title>Fetch Button Demo</title> | |
| <script type="module" src="/build/designsystem.esm.js"></script> | |
| <script nomodule src="/build/designsystem.js"></script> |
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
| function wrapPromise(promise) { | |
| let status = "pending"; | |
| let result; | |
| let suspender = promise.then( | |
| r => { | |
| status = "success"; | |
| result = r; | |
| }, | |
| e => { | |
| status = "error"; |
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 IndexList = ({ prefetchedIndexes }) => { | |
| const data = usePrefetchedQuery(prefetchedIndexes); | |
| return data.majorIndexesList.map(index => ( | |
| <div key={index.ticker}> | |
| Show {index.ticker} | |
| </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
| const App = () => { | |
| const [prefetchedIndexes, setPrefetchedIndexes] = useState(); | |
| return ( | |
| <> | |
| <button | |
| onClick={() => { | |
| setPrefetchedIndexes(prefetchQuery(`${API}/majors-indexes`)); | |
| }} | |
| > |
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 useIncrement = (defaultValue = 0) => { | |
| const [value, setValue] = useState(defaultValue); | |
| const increment = useCallback(() => setValue(value => value + 1), []); | |
| return [value, increment]; | |
| }; | |
| const ExampleWithCustomHook = () => { | |
| const [a, incrementA] = useIncrement(); |
NewerOlder