Skip to content

Instantly share code, notes, and snippets.

@Devcon4
Devcon4 / plugin.ts
Created April 24, 2018 02:17
Fun with dynamic literals!
const number = /(?:sbyte|ushort|short|uint|int|ulong|long|float|double|decimal|byte)/;
const string = /(?:char|string)/;
const bool = /(?:bool)/;
const date = /(?:DateTime)/;
let builder = {
accessModifier: 'public',
name: 'test',
type: 'int'
};
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
type rule<T> = {[key in FunctionPropertyNames<T>]?: T[key] extends (args: infer U) => void ? U : never};
class rules {
ruleOne(args: {first: string, second: number}) { }
}
function ruleTwo(args: {first: number}) { }
@Devcon4
Devcon4 / action.ts
Last active November 7, 2020 23:30
httpClient
export class Action<T> {
_subject = new BehaviorSubject<T>(undefined);
public get state() : T {
return this._subject.getValue();
}
public set state(v : T) {
this._subject.next(v);
getCitation = this.ds.citation.getAllForProcedure.bind(this, pipe(Dispatch(this.store, this.getCitation), Spinner(this.store)));
getCitations(procId: number): Observable<CitationBasic> {
return this.httpGet(
this.getCitations,
'/inspections/api/action/Citation/GetAllForProcedure?procId=' + procId,
x => new CitationBasic(x)
);
}
@Devcon4
Devcon4 / Action.ts
Last active May 30, 2018 16:30
Example of state
export class Action<T> {
_subject = new BehaviorSubject<T>(undefined);
public get state() : T {
return this._subject.getValue();
}
public set state(v : T) {
this._subject.next(v);
/* tslint:disable:no-unused-variable */
type booleanify<T> = { [P in keyof T]: boolean };
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { AppState, Store, dataReducer, DataActions, MiscActions } from '../../../cdux';
import { async, inject } from '@angular/core/testing';
import * as moment from 'moment';
import { ProcedureSchedulerComponent } from '../../../component/scheduleTools/procedureScheduler/procedureScheduler.component';
export interface IActionable<T> {
state: T;
subject: BehaviorSubject<T>;
}
export class Action<T> {
_subject = new BehaviorSubject<T>(undefined);
public get state() : T {
type funcPropNames<T> = {
[prop in keyof T]: T[prop] extends Function ? prop : never;
}[keyof T];
type FunctionProps<T> = Pick<T, funcPropNames<T>>;
export type Spied<T> = {
[k in keyof T]: k extends FunctionProps<T> ? jasmine.Spy : T;
};
export type Spied<T> = {
[K in keyof T]: T[K] extends Function ? jasmine.Spy : T[K] extends object ? Spied<T[K]> : T[K];
};
export function spyOnClass<T, U1 extends unknown[]>(type: new (...tArg1: U1) => T, ...arg1: U1) {
let spyOnFunctions = function <W>(obj: W): Spied<W> {
Object.keys(obj).forEach(p => {
if (!!obj && !arg1.some(a => obj[p] === a)) {
if (obj[p] instanceof Function) {
spyOn(obj, p as keyof W);
public interface ISendEmail<in T>
{
void SendEmail(T param);
}
public interface ISendInApp<in T>
{
void SendInApp(T param);
}