-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
115 additions
and
67 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const React = require('inferno-compat') | ||
const createContext = require('create-react-context/lib/implementation') | ||
|
||
Object.keys(React).forEach(key => { | ||
if (key === 'default' || key === '__esModule') return | ||
exports[key] = React[key] | ||
}) | ||
|
||
// bypass export of React.createContext | ||
exports.createContext = createContext | ||
exports.default = React.default |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { sampleUserData } from '../../../utils/sample-data' | ||
|
||
export default (req: NextApiRequest, res: NextApiResponse) => { | ||
try { | ||
const { id } = req.query; | ||
const selected = sampleUserData.find(data => data.id === Number(id)) | ||
|
||
if (!selected) { | ||
throw new Error('Cannot find user') | ||
} | ||
|
||
res.status(200).json(selected) | ||
} catch (err) { | ||
res.status(404).json({ statusCode: 404, message: err.message }) | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { sampleUserData } from '../../../utils/sample-data' | ||
|
||
export default (_: NextApiRequest, res: NextApiResponse) => { | ||
try { | ||
if (!Array.isArray(sampleUserData)) { | ||
throw new Error('Cannot find user data') | ||
} | ||
|
||
res.status(200).json(sampleUserData) | ||
} catch (err) { | ||
res.status(500).json({ statusCode: 500, message: err.message }) | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,13 @@ | ||
import { User } from '../interfaces' | ||
|
||
/** Dummy user data. */ | ||
export const dataArray: User[] = [ | ||
{ id: 101, name: 'Alice' }, | ||
{ id: 102, name: 'Bob' }, | ||
{ id: 103, name: 'Caroline' }, | ||
{ id: 104, name: 'Dave' }, | ||
] | ||
|
||
/** | ||
* Calls a mock API which finds a user by ID from the list above. | ||
* | ||
* Throws an error if not found. | ||
*/ | ||
export async function findData(id: number | string) { | ||
const selected = dataArray.find(data => data.id === Number(id)) | ||
|
||
if (!selected) { | ||
throw new Error('Cannot find user') | ||
} | ||
|
||
return selected | ||
} | ||
|
||
/** Calls a mock API which returns the above array to simulate "get all". */ | ||
export async function findAll() { | ||
// Throw an error, just for example. | ||
if (!Array.isArray(dataArray)) { | ||
throw new Error('Cannot find users') | ||
import fetch from 'isomorphic-unfetch' | ||
|
||
export async function sampleFetchWrapper( | ||
input: RequestInfo, | ||
init?: RequestInit | ||
) { | ||
try { | ||
const data = await fetch(input, init).then(res => res.json()) | ||
return data | ||
} catch (err) { | ||
throw new Error(err.message) | ||
} | ||
|
||
return dataArray | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { User } from '../interfaces' | ||
|
||
/** Dummy user data. */ | ||
export const sampleUserData: User[] = [ | ||
{ id: 101, name: 'Alice' }, | ||
{ id: 102, name: 'Bob' }, | ||
{ id: 103, name: 'Caroline' }, | ||
{ id: 104, name: 'Dave' }, | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
"registry": "https://registry.npmjs.org/" | ||
} | ||
}, | ||
"version": "9.1.2-canary.3" | ||
"version": "9.1.2-canary.4" | ||
} |
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
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
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
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
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
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