Skip to content

Instantly share code, notes, and snippets.

View apostolos's full-sized avatar

Apostolos Tsakpinis apostolos

  • WebHotelier | primalRES
  • Athens, Greece
  • 19:38 (UTC +03:00)
  • X @apostolos
View GitHub Profile
@apostolos
apostolos / machine.js
Created January 5, 2021 19:03
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// @flow
import * as React from 'react';
import ReactDOM from 'react-dom';
type Props = {
children: React.Node,
containerRef?: (el: ?HTMLElement) => void,
};
/**
function downloadFiles(files /*: Array<string> */) {
// Do not fetch more than 8 files at a time
const PARALLEL_DOWNLOADS = Math.min(8, files.length);
// Create an Iterator from the array, this is our download queue
const queue = files[Symbol.iterator]();
// Channels are our download workers. As soon as a channel finishes downloading a file,
// it begins fetching another file from the queue. Best effort
const channels = [];
// Create only PARALLEL_DOWNLOADS number of channels
@apostolos
apostolos / Portal.jsx
Last active September 14, 2017 16:15
import * as React from 'react';
import ReactDOM from 'react-dom';
/**
* This component detaches its contents and re-attaches them to document.body (using ReactDOM.createPortal).
* Use it when you need to circumvent DOM z-stacking (for dialogs, popovers, etc.).
*/
class Portal extends React.Component {
targetElement = null;
// Let's say we want to scroll to #my-target
flipScroll('my-target');
const flipScroll = (trg) => {
const trgEl = document.getElementById(trg);
// Store current scroll
const prevScroll = getScrollTop();
// Perform the scroll
.flip-translate {
animation: no-translate-3d 1s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}
@keyframes no-translate-3d {
to {
transform: translate3d(0, 0, 0);
}
}

Keybase proof

I hereby claim:

  • I am apostolos on github.
  • I am apostolos (https://keybase.io/apostolos) on keybase.
  • I have a public key whose fingerprint is EA74 B7F8 1AA3 464E C3A1 2D95 ED4B 97F6 AC25 8736

To claim this, I am signing this object:

import React from 'react'
let firstRoute = true;
export default (getComponent) => class AsyncComponent extends React.Component {
static Component = null;
mounted = false;
// Remembers scroll positions based on location->key