Skip to content

Instantly share code, notes, and snippets.

export const jsx = (type, props = {}, key = null) => ({
key,
type,
props
});
export const Fragment = (props = {}) => props.children;
const NoFlags = 0b0000000;
const Placement = 0b0000001;
const HTML_TAGS =
`html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot`.split(
","
);
const specialBooleanAttrs =
`itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`.split(
","
);
function shallowEqual(objA, objB) {
if (Object.is(objA, objB)) {
return true;
}
if (typeof objA !== 'object' || typeof objB !== 'object'
|| typeof objA === 'null' || typeof objB === 'null'
) {
return false;
}
@AimWhy
AimWhy / scopeFix.js
Last active February 27, 2023 03:35
const config = { attributes: true, childList: true, subtree: true };
const traverseFiber = (fiber, call, param1) => {
if (fiber) {
call(fiber, param1);
let child = fiber.child;
while (child) {
traverseFiber(child, call, param1);
child = child.sibling;
}
import * as React from 'react';
import * as ReactDOM from 'react-dom';
const REACT_ELEMENT_TYPE = Symbol.for('react.element');
const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
function isForward(object) {
if (typeof object === 'object' && object !== null) {
const $$typeof = object.$$typeof;
const type = object.type;
import { useEffect, useReducer, useRef } from 'react';
export const useConstant = (compute) => {
const ref = useRef(null);
if (ref.current === null) {
ref.current = compute();
}
return ref.current;
};
let config = {};
const containerMap = {};
const remoteMap = {};
let isDefaultScopeInitialized = false;
async function lookupExposedModule(key, exposedModule) {
const container = containerMap[key];
const factory = await container.get(exposedModule);
const Module = factory();
return Module;
@AimWhy
AimWhy / run.js
Last active December 28, 2022 06:05
function isPromise(obj) {
return (
Boolean(obj) &&
(typeof obj === 'object' || typeof obj === 'function') &&
typeof obj.then === 'function' &&
typeof obj.catch === 'function'
);
}
function run(fn, args = [], { raceStampKey = 'raceStamp', timestamp } = {}) {
const throwFatalError = () => {
throw new Error('Something went wrong.');
};
export function dataLoader(batchLoader) {
let pendingItems = null;
let dispatchTimer = null;
const destroyTimerAndPendingItems = () => {
clearTimeout(dispatchTimer);
import React from 'react';
import useForceUpdate from './use-force-update';
import useLayoutEffect from './useIsomorphicLayoutEffect';
export const createSlots = (slotNames) => {
const SlotsContext = React.createContext({
registerSlot: () => null,
unregisterSlot: () => null,
context: {},
});