This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { throttle } from "lodash"; | |
/** | |
* Mouse position as a tuple of [x, y] | |
*/ | |
type MousePosition = [number, number]; | |
/** | |
* Hook to get the current mouse position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { useMousePosition } from "~/hooks/useMousePosition"; | |
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */ | |
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) { | |
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {}; | |
const [mouseX, mouseY] = useMousePosition(); | |
const positions = { x, y, h, w, mouseX, mouseY }; | |
return ( | |
<div |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
export function makeLoadable({ loading, render, loader }) { | |
const Comp = render | |
? React.lazy(() => | |
loader().then(loaded => ({ | |
...loaded, | |
default: props => render(loaded, props), | |
})) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exception InvalidValue(string); | |
let toInt = f => (f +. 0.5)->int_of_float; | |
module Constants = { | |
let kn = 18; | |
let xn = 0.950470; | |
let yn = 1.; | |
let zn = 1.088830; | |
let t0 = 0.137931034; // 4 / 29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type update('state, 'action) = | |
| NoUpdate | |
| Update('state) | |
| SideEffects(self('state, 'action) => unit) | |
| UpdateWithSideEffects('state, self('state, 'action) => unit) | |
and self('state, 'action) = { | |
state: 'state, | |
send: 'action => unit, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type date = {day: int}; | |
type eventName = | |
| SetDate | |
| SetText; | |
let setDate send (u: date) => send SetDate u; | |
let handleSetDate on (handler: _ => date => unit) => on SetDate handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DelayRender extends React.Component { | |
constructor({onPropsChange, ...props}) { | |
super(...arguments) | |
this.state = {props} | |
} | |
componentWillReceiveProps(props) { | |
this.setState({isWaiting: true}) | |
this.props.onPropsChange(() => {this.setState({props, isWaiting: false})}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST_CONFIG = NODE_ENV=test BABEL_ENV=test | |
test-unit: | |
$(TEST_CONFIG) mocha app/**/*_spec.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = React.createClass | |
displayName: 'LazyRender' | |
getInitialState: -> props: @props | |
componentWillReceiveProps: (newProps) -> setTimeout (=> @setState newProps), 10 | |
shouldComponentUpdate: (newProps, newState) -> @state isnt newState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Style = require '../styles/generated/props' | |
module.exports = React.createClass | |
displayName: 'grid' | |
propTypes: | |
className: React.PropTypes.string | |
getInitialState: -> |
NewerOlder