Skip to content

Instantly share code, notes, and snippets.

@Offirmo
Last active February 20, 2024 08:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Offirmo/a4244fe622cf63d4bdf4f1acb845d59a to your computer and use it in GitHub Desktop.
[JS common libs usage] #JavaScript #TypeScript
import EventEmitter from 'emittery'
const EMITTER_EVT = 'change'
const emitter = new EventEmitter<{ [EMITTER_EVT]: string }>()
emitter.emit(EMITTER_EVT, `[in-mem]`)
const unbind = emitter.on(EMITTER_EVT, (src: string) => { ... })
////////////////////////////////////
import fetch_ponyfill from 'fetch-ponyfill'
const { fetch, Request, Response, Headers } = fetch_ponyfill()
////////////////////////////////////
import debounce from 'lodash/debounce'
////////////////////////////////////
/*
"memoize-one": "^5",
"@types/memoize-one": "^4",
*/
import memoize_one from 'memoize-one'
const get_derived: GetDerived = memoize_one(get_derived_unmemoized)
////////////////////////////////////
// "tiny-invariant": "^1",
import assert from 'tiny-invariant'
assert(
typeof defaultValue !== 'undefined',
`getFeatureFlag: a default value must be provided when querying "${featureFlagName}"!`,
)
////////////////////////////////////
// "dequal": "^2",
import { dequal as is_deep_equal } from 'dequal'
assert(is_deep_equal(eventual_state_hint, store_state), 'dispatcher: state hint = store state')
////////////////////////////////////
// https://github.com/dphilipson/typescript-string-enums
// npm i typescript-string-enums
// yarn add typescript-string-enums
import { Enum } from 'typescript-string-enums'
// tslint:disable-next-line: variable-name
export const MarkName = Enum(
'initialBundleRequested',
'initialBundleLoaded',
'appStarted',
'reactStarted',
'userLoggedIn',
'userAttemptedLogin'
)
export type MarkName = Enum<typeof MarkName> // eslint-disable-line no-redeclare
/////
Enum.keys(enum)
Enum.values(enum)
if (!Enum.isType(Color, colorString)) {
throw new Error(`${colorString} is not a valid color`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment