Skip to content

Instantly share code, notes, and snippets.

@jquense
jquense / Observable.ts
Created December 5, 2022 16:48
tiny observable implementation
export interface Subscription {
readonly closed: boolean;
unsubscribe: () => void;
}
export interface Observer<T> {
closed: boolean;
error: (error: any) => void;
complete: () => void;
next: (value: T) => void;
@jquense
jquense / ts-workspaces-doctor.js
Created November 12, 2019 14:34
Configure a yarn workspaces to use project references and paths
/* eslint-disable no-param-reassign */
const { promises: fs, readFileSync } = require('fs');
const path = require('path');
const prettier = require('prettier');
const { parse, stringify } = require('comment-json');
const getWorkspaces = require('get-workspaces').default;
const findWorkspacesRoot = require('find-workspaces-root').default;
const safeRequire = m => {
function useEventCallback(fn) {
const ref = useRef(fn)
useLayoutEffect(() => {
ref.current = fn;
}, [fn]);
return useCallback(() => {
const fn = ref.current;
return fn();
@jquense
jquense / createStore.js
Created November 1, 2018 18:39
redux react hooks
import React, { useReducer, useContext, useMemo } from 'react'
import get from 'lodash/get'
import invariant from 'invariant'
const INIT = {
type: `INIT${Math.random()
.toString(36)
.substring(7)
.split('')
.join('.')}`,
const { utils } = require('react-docgen');
const { default: resolveHOC } = require('react-docgen/dist/utils/resolveHOC');
const {
default: resolveToModule,
} = require('react-docgen/dist/utils/resolveToModule');
module.exports = ({ moduleName = 'styled-components' } = {}) => {
const isStyledExpression = (tagPath, t) =>
(t.CallExpression.check(tagPath.node) &&
tagPath.get('callee').node.name === 'styled') ||
@jquense
jquense / MainModulesPlugin.js
Created February 16, 2018 17:15
Main Module plugin webpack, concord
const concord = require('enhanced-resolve/lib/concord');
const getInnerRequest = require('enhanced-resolve/lib/getInnerRequest');
const createInnerCallback = require('enhanced-resolve/lib//createInnerCallback');
const defaultConfig = {
'./lib/**': './src/**',
};
function normalizeCondition(condition) {
let normalized = [].concat(condition);
@jquense
jquense / FormExample.js
Last active October 5, 2016 17:04 — forked from insin/FormExample.js
React Form Example / Live version: http://react-form-example.surge.sh/
import React from 'react'
import Form from 'react-formal'
import {
Alert,
Button,
Col, ControlLabel,
Form as BsForm, FormControl, FormGroup as BsFormGroup,
HelpBlock,
} from 'react-bootstrap'
class Form extends React.Component {
constructor() {
super()
this.state = {
name: null
}
}
@jquense
jquense / ScrollSpy.js
Created March 24, 2016 19:57
React ScrollSpy
import React, { PropTypes } from 'react';
import { findDOMNode } from 'react-dom'
import getOffset from 'dom-helpers/query/offset';
let ScrollSpy = React.createClass({
childContextTypes: {
$scrollSpy: PropTypes.shape({
anchor: PropTypes.func,
activeTarget: PropTypes.string
})
import React from 'react';
import cn from 'classnames';
import RootCloseWrapper from 'react-overlays/lib/RootCloseWrapper';
let MenuPanel = React.createClass({
getDefaultProps(){
return {
bsRole: 'menu',
rootClose: true