This file contains hidden or 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
export {}; | |
/* | |
Taken from https://gist.github.com/sechel/e6aff22d9e56df02c5bd09c4afc516e6 | |
which is the basis for https://github.com/JSmith01/broadcastchannel-polyfill | |
but rewritten into TypeScript and class rather than JS with .prototype extension | |
*/ | |
const channels: Record<string, Set<BroadcastChannel>> = {}; |
This file contains hidden or 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 { useEffect } from 'react'; | |
/** | |
* @example | |
* useKeyDown('escape', cancel); | |
*/ | |
export function useKeyDown(keys: string, onKeyDown: Listener): void; | |
/** | |
* @example | |
* useKeyDown({ 'cmd + z': undo, 'cmd + z': redo }); |
This file contains hidden or 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
function getUserName(user: { name?: string; fullName: string }) { | |
return user.name || user.fullName.split(' ')[0]; | |
} | |
describe('getUserName', () => { | |
it('should return name if it exists', () => { | |
const name = 'name'; | |
const result = getUserName({ name } as any); | |
// TypeScript would error ^^^^^^^^ | |
// if we didn't cast it |
This file contains hidden or 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
Show hidden characters
{ | |
"include": ["src/**/*"], | |
"exclude": ["src/**/*.spec.*"], | |
"compilerOptions": { | |
"outDir": "dist", | |
"rootDir": "src", | |
"module": "esnext", | |
"moduleResolution": "node", | |
"target": "es2019", |
This file contains hidden or 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 { ApplicationRef, NgModuleRef } from '@angular/core'; | |
import { createNewHosts } from '@angularclass/hmr'; | |
import { ActionReducer } from '@ngrx/store'; | |
export function hmrMetaReducer(reducer: ActionReducer<any>) { | |
return (state: any, action: any) => | |
action.type === 'SET_ROOT_STATE' | |
? action.payload | |
: reducer(state, action); | |
} |
This file contains hidden or 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
function Heap(compare = (target, parent) => target > parent) { | |
this.array = []; | |
this.compare = compare; | |
} | |
Object.defineProperty(Heap.prototype, 'size', { get: function () { return this.array.length; } }) | |
Heap.prototype.peek = function () { return this.array[0]; } | |
Heap.prototype.pop = function () { |
This file contains hidden or 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
public class Expect | |
{ | |
private object expectation; | |
protected bool not; | |
public Expect(object expectation) | |
{ | |
this.expectation = expectation; | |
} |