Skip to content

Instantly share code, notes, and snippets.

View jamiewinder's full-sized avatar

Jamie Winder jamiewinder

View GitHub Profile
@jamiewinder
jamiewinder / detectexternalclick.tsx
Created November 22, 2018 16:05
Portal-friendly external event detection
import React from 'react';
import { DetectExternalEvents } from './detectexternalevents';
const EXTERNAL_REACT_EVENTS = ['onMouseDown', 'onTouchStart'];
const EXTERNAL_DOM_EVENTS = ['mousedown', 'touchstart'];
export interface IDetectExternalClickProps {
component?: string;
onExternalClick: (event: Event) => void;
@jamiewinder
jamiewinder / repository.ts
Created March 2, 2017 13:56
Example Repository
class DataRecord<T> {
// Constructor
constructor(value: T, initialRef: any) {
this.value = value;
this.refs = new Set([initialRef]);
}
// Properties
public readonly value: T;
public readonly refs: Set<any>;
@jamiewinder
jamiewinder / observablerepository.ts
Last active March 2, 2017 16:14
Example ObservableRepository
import { observable, computed, ObservableMap } from 'mobx';
import { objectUid } from './objectuid';
export type KeyType = string | number | object;
export type RefType = string | number | object;
function keyFn(key: KeyType) {
if (typeof key === 'string') {
return key;