Skip to content

Instantly share code, notes, and snippets.

@Rwin90
Rwin90 / mock-decorator.ts
Created September 9, 2020 06:14
Mock Decorator for angular service
import {environment} from "../../../environments/environment";
export type ClassConstructor = {new(...args:any[]):{}, prototype: any};
export interface MockingParams<T, K> {
mockClass: T;
targetMembers: K[];
force?: boolean;
}
import { Injectable } from '@angular/core';
import {Subject} from 'rxjs/Rx';
import {PlatformLocation} from '@angular/common';
@Injectable()
export class WebWorkerService {
worker;
workerResult: {[key: string]: Subject<any> } = {} ;
workerUrl = window.location.origin +this.platformLocation.getBaseHrefFromDOM() + 'assets/scripts/worker.js';
@Rwin90
Rwin90 / cloudSettings
Last active September 9, 2020 06:12
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-04-19T15:11:42.157Z","extensionVersion":"v3.2.9"}
@Rwin90
Rwin90 / utils.js
Last active September 9, 2020 06:11
/**
* Get an item from an array collection by id
*/
const getByIdFromArray = module.exports.getByIdFromArray = function getByIdFromArray(collection = []) {
return function(id = '') {
return collection.find((item = {}) => item.id === id);
}
}
/**
@Rwin90
Rwin90 / waitForEach.js
Created March 25, 2018 08:53
a generic function that sequencialy run a function on a promiss array
const waitForEach = (processFunc , [head, ...tail]) =>
!head
? Promise.resolve()
: processFunc(head).then(waitForEach(processFunc , tail));
// example of usage
@Rwin90
Rwin90 / click-outside.directive.ts
Created March 18, 2018 10:14
angular 4 directive that emit an event when click event happen outside of target
import {Directive, ElementRef, Output, EventEmitter, HostListener} from '@angular/core';
@Directive({
selector: '[appClickOutside]'
})
export class ClickOutsideDirective {
constructor(private _elementRef: ElementRef) {
}
@Output()
@Rwin90
Rwin90 / its-my-scroll.directive.ts
Last active May 15, 2018 09:03
its an angular 4+ directive that prevent parent element scroll after child element scroll rich to end
import {Directive, ElementRef, HostListener} from '@angular/core';
@Directive({
selector: '[appMyScroll]'
})
export class ItsMyScrollDirective {
constructor(private _elementRef: ElementRef ) {
}