Skip to content

Instantly share code, notes, and snippets.

View KeithGillette's full-sized avatar
💭
Incessantly Optimizing

Keith Gillette KeithGillette

💭
Incessantly Optimizing
View GitHub Profile
@KeithGillette
KeithGillette / apollo-angular-mutation-watch.ts
Created March 21, 2019 21:47
Apollo-Angular Monkey Patch Allowing Watched Queries Updates to be triggered by mutations <https://github.com/apollographql/apollo-feature-requests/issues/97>
import ApolloClient, { ApolloClientOptions, ApolloQueryResult, MutationOptions, MutationUpdaterFn, ObservableQuery, OperationVariables, WatchQueryOptions } from 'apollo-client';
import { DocumentNode } from 'graphql';
import { FetchResult } from 'apollo-link';
import { DataProxy } from 'apollo-cache';
import { QueryRef } from 'apollo-angular';
import { R } from 'apollo-angular/types';
interface IMutationUpdateEvent<T = any> {
mutation: DocumentNode;
dataProxy: DataProxy;
@KeithGillette
KeithGillette / duck-type-equivalent.method.ts
Created February 5, 2018 21:54
TypeScript Type Guard: Duck Type Equivalent To Class
export interface IClassConstructor<T> {
new (...args: any[]): T;
}
/** generic TypeScript Type Guard
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
*/
export function isDuckTypeEquivalentToClass<T>(objectToTest: any, classToTest: IClassConstructor<T>): objectToTest is T {
if (objectToTest instanceof classToTest) {
return true;
@KeithGillette
KeithGillette / MessageService.ts
Last active February 5, 2018 21:23
Simple TypeScript Message Bus (supporting Angular DI)
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs/Rx';
import { filter, map } from 'rxjs/operators';
export interface IClassConstructor<T> {
new (...args: any[]): T;
}
export interface IMessage {
channel: Function;
/**
* @description Configures an CreateOverrideableArray generator function returning arrays with provided array methods overriden or added
* @param {{ 'functionName': { 'functionToApply': () => any, 'overrideNativeMethod'?: boolean } }} configuration - configuration object
* @returns {function: any[]} CreateOverriddenArray - returns an array of provided parameters with array methods configured
*/
export function ConfigureOverridableArrayFactory(configuration: {}) {
const callingContext = this;
const protoIsSupported = { __proto__: [] } instanceof Array; // Test browser for __proto__ property support
// save all standard array methods in a list
const anArray: any[] = new Array();