Skip to content

Instantly share code, notes, and snippets.

View quisido's full-sized avatar
🌸
trying my best

quisi.do quisido

🌸
trying my best
View GitHub Profile
@quisido
quisido / setup.js
Last active April 1, 2019 01:24
Implementing Quicksort in JavaScript
const quickSort = (
unsortedArray,
comparator = defaultComparator
) => {
// Create a sortable array to return.
const sortedArray = [...unsortedArray];
// Recursively sort sub-arrays.
const recursiveSort = (start, end) => {
@quisido
quisido / default.js
Last active February 13, 2019 16:51
Implementing Quicksort in JavaScript
const defaultComparator = (a, b) => {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
};
@quisido
quisido / baseline.js
Created November 20, 2018 17:22
Implementing Quicksort in JavaScript
const quickSort = (unsortedArray) => {
const sortedArray = TODO(unsortedArray);
return sortedArray;
};
@quisido
quisido / lifespan.ts
Last active November 1, 2018 01:10
React Suspense with the Fetch API
// NEW: lifespan parameter
const useFetch = (
input: RequestInfo,
init?: RequestInit | undefined,
lifespan: number = 0
) => {
// ...
const fetchCache: FetchCache = {
@quisido
quisido / suddenly-typescript.ts
Created November 1, 2018 01:03
React Suspense with the Fetch API
const deepEqual = require('deep-equal');
interface FetchCache {
fetch?: Promise<void>;
error?: any;
init: RequestInit | undefined;
input: RequestInfo;
response?: any;
}
@quisido
quisido / example.js
Created November 1, 2018 00:46
React Suspense with the Fetch API
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>;
@quisido
quisido / suspense-promise.js
Last active May 27, 2023 12:24
React Suspense with the Fetch API
class Suspense extends React.Component {
constructor(props) {
super(props);
this.state = {
promise: null
};
}
componentDidCatch(e) {
@quisido
quisido / suspense.js
Created November 1, 2018 00:22
React Suspense with the Fetch API
class Suspense extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null
};
}
componentDidCatch(e) {
@quisido
quisido / reactn-app.js
Created October 31, 2018 17:24
Replacing Redux with ReactN to reduce complexity and bundle size
import React, { Component } from 'reactn';
import './App.css';
class App extends Component {
componentDidMount() {
this.setGlobal(
fetch('index.html')
.then(response => response.text())
.then(html => ({
@quisido
quisido / reactn.js
Last active October 31, 2018 23:50
Replacing Redux with ReactN to reduce complexity and bundle size
import React from 'react';
import { setGlobal } from 'reactn';
import ReactDOM from 'react-dom';
import App from './App';
setGlobal({
data: null,
x: 0
});