Skip to content

Instantly share code, notes, and snippets.

View panzerdp's full-sized avatar

Dmitri Pavlutin panzerdp

View GitHub Profile
@panzerdp
panzerdp / decoratedFetch.ts
Last active September 18, 2022 23:51
An extensible fetch() implementation that uses the decorator pattern
type ResponseWithData = Response & { data?: any };
interface Fetcher {
run(input: RequestInfo, init?: RequestInit): Promise<ResponseWithData>;
}
class BasicFetcher implements Fetcher {
async run(input: RequestInfo, init?: RequestInit): Promise<ResponseWithData> {
return await fetch(input, init);
}
@panzerdp
panzerdp / app.jsx
Created July 8, 2017 07:56
Extract user data to component map method
class App extends React.Component {
//....
render() {
return (
<div>
<h1>Users</h1>
<ul>
{this.state.users.map(this.userDataToComponent)}