Skip to content

Instantly share code, notes, and snippets.

View rarmatei's full-sized avatar
🐔

Rares Matei rarmatei

🐔
  • Nrwl.io
  • Glasgow, UK
View GitHub Profile
class AmountInput {
private static MAX_ALLOWED = 99_999_999;
amount: number = 0;
showTooltip() {
//show tooltip
setTimeout(() => {
//hide tooltip
}, 2_500);
import React from "react";
function Results() {
return (
<table>
<tr>
<th> Title </th>
<th> First name </th>
<th> Surname </th>
<th> Email </th>
@rarmatei
rarmatei / typeguards.ts
Last active February 22, 2018 22:03
typescript type guards
class Book {
title: string;
}
class Television {
screenSize: string;
}
function relaxWith(item: Book | Television) {
if(item instanceof Book) {
class MyService3 {
constructor() {
this._producer = Rx.Observable.of(1)
.publish();
}
private _producer: Rx.ConnectableObservable<number>;
startItUp(): Rx.Observable<number> {
class MyService {
constructor() {
this._producer = Rx.Observable.of(1)
.publish();
}
private _producer: Rx.ConnectableObservable<number>;
startItUp(): Rx.Observable<number> {
class MyService {
constructor() {
this._producer = Rx.Observable.interval(1000)
.publish();
}
private _producer: Rx.ConnectableObservable<number>;
startItUp(): Rx.Observable<number> {
function delayedRefCount(delay) {
return (source) => {
const subscribeUpdates = new Subject();
let trackerConnection;
let subscriptionTracker = subscribeUpdates.scan((total, change) => change + total, 0)
.switchMap(count => {
return count === 0
? Observable.timer(delay)
.do(_ => source.connect().unsubscribe() || trackerConnection.unsubscribe())
: Observable.never();
subscribeUpdates
.scan((total, change) => change + total, 0)
.switchMap(count => {
return count === 0
? Observable.timer(delay)
.do(_ => /* tear-down logic */ )
: Observable.never();
});
function delayedRefCount(delay) {
return (source) => {
let length = 0;
let timeout;
const onNewSubscriber = () => {
const onUnsubscribe = () => {
length--;
if (length === 0) {
timeout = setTimeout(() => {
source.connect().unsubscribe();
function refCount(source) {
let length = 0;
const onNewSubscriber = () => {
const onUnsubscribe = () => {
length--;
if(length === 0) {
source.connect().unsubscribe();
}
};
length++;