Skip to content

Instantly share code, notes, and snippets.

View charlintosh's full-sized avatar
🏠
Working from home

Carlos Gómez Suárez charlintosh

🏠
Working from home
View GitHub Profile
import * as React from "react";
import "./Nav.component.scss";
import {useObservable} from "rxjs-hooks";
import {watchScroll$} from "./nav.service";
import {ScrollMovement, ScrollType} from "./types";
// other imports
function Nav(): JSX.Element {
const scrollDirection: ScrollType = useObservable(watchScroll$, ScrollMovement.UP);
import { Observable, animationFrameScheduler, fromEvent, of } from "rxjs";
import { distinctUntilChanged, filter, map, pairwise, switchMap, throttleTime } from "rxjs/operators";
import { ScrollType, ScrollMovement } from "./types";
export const watchScroll$ = (): Observable<ScrollType> =>
of(typeof window === "undefined")
.pipe(
filter((undefinedWindow) => (!undefinedWindow)),
switchMap(() => fromEvent(window, "scroll", {passive: true})),
throttleTime(0, animationFrameScheduler),
import { Observable, animationFrameScheduler, fromEvent, of } from "rxjs";
import { distinctUntilChanged, filter, map, pairwise, switchMap, throttleTime } from "rxjs/operators";
import { ScrolType, ScrollMovement } from "./types";
export const watchScroll$ = (): Observable<ScrollType> =>
of(typeof window === "undefined")
.pipe(
filter((undefinedWindow) => (!undefinedWindow)),
switchMap(() => fromEvent(window, "scroll", {passive: true})),
throttleTime(0, animationFrameScheduler),
const axios = require('axios')
const doRequest = () => {
try {
return axios.get('https://thegreatapi.org/v1')
} catch (error) {
console.error(error)
}
}
@charlintosh
charlintosh / specificInterceptorSetup.tsx
Last active July 10, 2020 06:17
File that create an axios intance with the interceptors.
import {setupInterceptorsTo} from "./Interceptors";
import axios from "axios";
const specificAxios = setupInterceptorsTo(axios.createInstance());
@charlintosh
charlintosh / globalInterceptorSetup.tsx
Last active July 10, 2020 06:16
File that apply the interceptors to the global axios instance.
import {setupInterceptorsTo} from "./Interceptors";
import axios from "axios";
setupInterceptorsTo(axios);
@charlintosh
charlintosh / interceptor.js
Created July 3, 2020 19:08
Interceptor example
const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
@charlintosh
charlintosh / Interceptors.ts
Created July 3, 2020 19:05
Interceptors config file.
import {AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios";
const onRequest = (config: AxiosRequestConfig): AxiosRequestConfig => {
console.info(`[request] [${JSON.stringify(config)}]`);
return config;
}
const onRequestError = (error: AxiosError): Promise<AxiosError> => {
console.error(`[request error] [${JSON.stringify(error)}]`);
return Promise.reject(error);