Skip to content

Instantly share code, notes, and snippets.

@bisubus
bisubus / main.js
Created August 4, 2021 09:44 — forked from bponomarenko/main.js
Custom implementation of the missing onAbort hooks in vue-router
import Vue from 'vue';
import VueRouter from 'vue-router';
import applyOnRouterAbortShim from './on-router-abort-shim';
Vue.use(VueRouter);
const router = new VueRouter(...);
applyOnRouterAbortShim(router);
@bisubus
bisubus / global-detection.js
Created June 7, 2020 10:02
Cross-platform global variable detection with fallbacks
// self is window proxy in IE<=10, eval handles this
var _global = (function () { try { return Function('return this')() } catch (e) {} })() // browsers without CSP, Node
|| typeof globalThis !== 'undefined' && globalThis // new and polyfilled browsers/workers CSP, newer Node with broken eval
|| typeof self !== 'undefined' && self // old browsers/workers with CSP
|| typeof global !== 'undefined' && global // old Node with broken eval
|| typeof window !== 'undefined' && window; // fallback for exotic environments
@bisubus
bisubus / . Desugared generator & async generator functions
Last active November 24, 2019 19:03
Desugared generator & async generator functions (for..of & for await..of)
@bisubus
bisubus / ES5-compatible extendable ES6 Promise class
Last active November 20, 2019 23:02
Extendable Promise subclass inheritance that works with Babel or TypeScript ES5 target
// inherits from promise class through the chain
new ExtendablePromise(resolve => resolve()).then() instanceof Promise === true
// inherits from promise subclass through the chain
new ExtendablePromise(resolve => resolve()).then() instanceof ExtendablePromise === true
// allows for direct calls for ES5 inheritance
ExtendablePromise.call(Object.create(ExtendablePromise.prototype), resolve => resolve()).then()
@bisubus
bisubus / client.js
Created September 29, 2017 05:25 — forked from damonYuan/client.js
react server side rendering without redux (client side)
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory, useRouterHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import { configureStore } from './app/SpreeReactStore';
import routes from './app/routes';
let state = window.__initialState__ || undefined;
@bisubus
bisubus / renderRoute.js
Created September 29, 2017 05:25 — forked from damonYuan/renderRoute.js
react server side rendering without redux (server side)
// Helper function: Loop through all components in the renderProps object // and returns a new object with the desired key
let getPropsFromRoute = (renderProps, componentProps) => {
let props = {};
let lastRoute = renderProps.routes[-1];
renderProps.routes.reduceRight((prevRoute, currRoute) => {
componentProps.forEach(componentProp => {
if (!props[componentProp] && currRoute.component[componentProp]) {
props[componentProp] = currRoute.component[componentProp];
}
});
@bisubus
bisubus / Portal.js
Created September 25, 2017 11:11 — forked from lixiaoyan/Portal.js
React 16: Portal
import React from "react";
import PropTypes from "prop-types";
import { createPortal } from "react-dom";
class Portal extends React.Component {
static propTypes = {
children: PropTypes.node,
};
state = { mounted: false };
@bisubus
bisubus / entry.js
Created September 24, 2017 08:25 — forked from lixiaoyan/entry.js
React 16: ReactDOM.hydrate(...)
import React from "react";
import ReactDOM from "react-dom";
import { AppContainer } from "react-hot-loader";
import App from "./App";
const render = (hydrate = false) => {
const container = document.querySelector("#app");
const element = (
<AppContainer>
@bisubus
bisubus / ES5-ES6-ES2017-ES2019 omit & pick
Last active April 13, 2024 21:03
ES5/ES6/ES2017/ES2019 omit & pick