Skip to content

Instantly share code, notes, and snippets.

Avatar

Octave Raimbault dispix

  • Datadog
  • Paris
View GitHub Profile
@dispix
dispix / PropertyType.ts
Last active Oct 18, 2021
Gives a strong typing to string accessors like `lodash/get`
View PropertyType.ts
// Extracts the type of a property deeply nested in an object
// Example: DeepProperty<'foo[0].bar', { foo: Array<{ bar: { baz: string } }> }> === { baz: string }
export type PropertyType<
TModel extends Record<string, any>,
TPath extends string
> = TPath extends keyof TModel
? TModel[TPath]
: TPath extends `${infer Key}.${infer RemainingPath}`
? Key extends keyof TModel
? PropertyType<TModel[Key], RemainingPath>
View useUpdate.js
import { useRef, useEffect } from 'react'
function useUpdate(fn) {
const mounting = useRef(true)
useEffect(() => {
if (mounting.current) {
mounting.current = false
} else {
fn()
}
View useUnmount.js
import { useEffect } from 'react'
function useUnmount(fn) {
useEffect(() => fn, [])
}
View useMount.js
import { useEffect } from 'react'
function useMount(fn) {
useEffect(() => void fn(), [])
}
@dispix
dispix / CHANGELOG.md
Last active Feb 15, 2021
OAUTH2 Authentication and token management with redux-saga
View CHANGELOG.md

Revision 5

  • Fix error parsing

Revision 4

  • Add missing yield in the login function

Revision 3

View class.jsx
* Player class
* @class
* @classdesc Construct a new player with an independent redux store
*/
class Player {
/**
* Class constructor
*/
constructor() {
/**
View designer.html
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-input/core-input.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../paper-item/paper-item.html">