Skip to content

Instantly share code, notes, and snippets.

View webhacking's full-sized avatar
👻
Hyper focusing

hax0r webhacking

👻
Hyper focusing
View GitHub Profile
@webhacking
webhacking / rxjs-example-04.ts
Created January 24, 2019 04:57
RxJS Example 04
import {from} from 'rxjs/internal/observable/from';
import {bufferCount, count, filter} from 'rxjs/operators';
const source = 'acbqibekboabkdnopenmenuckofqamdqlvopenmenuasdqweascqwekasdcnaskdeqweqwcasdopenmenu';
const sequence$ = from(source);
const matchSequence = 'openmenu';
sequence$
.pipe(
bufferCount(matchSequence.length, 1),
@webhacking
webhacking / rxjs-example-03.ts
Created January 24, 2019 04:55
RxJS Example 03
import {fromEvent} from 'rxjs/internal/observable/fromEvent';
import {interval} from 'rxjs/internal/observable/interval';
import {buffer, filter, map} from 'rxjs/operators';
let stream$ = fromEvent(document.getElementById('hit-me') as HTMLElement, 'click');
stream$
.pipe(
buffer(interval(3000)),
map((val: number[]) => val.length),
@webhacking
webhacking / rxjs-example-02.ts
Created January 24, 2019 04:53
RxJS Example 02
import {fromEvent} from 'rxjs/internal/observable/fromEvent';
import {buffer, map} from 'rxjs/operators';
import {interval} from 'rxjs/internal/observable/interval';
let stream$ = fromEvent(document.getElementById('hit-me'), 'click');
stream$
.pipe(
buffer(interval(3000)),
map((val) => val.length)
)
@webhacking
webhacking / rxjs-example-01.ts
Created January 24, 2019 04:39
RxJS Example 1
import {fromEvent} from 'rxjs/internal/observable/fromEvent';
const source$ = fromEvent(document.getElementById('hit-me'), 'click');
source$.subscribe((event: Event) => {
const currentClicked = ( event.currentTarget.getAttribute('number-of-clicked') ) ? event.currentTarget.getAttribute('number-of-clicked') : 1;
event.currentTarget.setAttribute('number-of-clicked', parseInt(currentClicked) + 1);
console.log(parseInt(currentClicked))
});
@webhacking
webhacking / replay-subject.example1.ts
Created January 24, 2019 04:36
Replay Subject Example -
const subject = new ReplaySubject(1 /* buffer size */);
@webhacking
webhacking / replay-subject.example.ts
Created January 24, 2019 04:22
Replay Subject Example
import {ReplaySubject} from 'rxjs/internal/ReplaySubject';
const subject = new ReplaySubject(2 /* buffer size */);
subject.next('a');
subject.next('b');
subject.next('c');
const subscription = subject.subscribe((x: string) => {
console.log(`Next: ${x}`);
@webhacking
webhacking / behavior-subject.example.ts
Created January 24, 2019 04:17
BehaviorSubject Example
/* Initialize with initial value of 42 */
import {BehaviorSubject} from 'rxjs/internal/BehaviorSubject';
const subject = new BehaviorSubject(42);
const subscription = subject.subscribe((x: number) => {
console.log(`Next: ${String(x)}`);
}, (error: Error) => {
console.log(`Error: ${error}`);
}, () => {
@webhacking
webhacking / async-subject.example.ts
Created January 24, 2019 02:53
AsyncSubject Example
import {AsyncSubject} from 'rxjs/internal/AsyncSubject';
let subject = new AsyncSubject;
let i = 0;
const handle = setInterval(() => {
subject.next(i);
if (++i > 3) {
subject.complete();
clearInterval(handle);
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [ "es6", "dom" ],
"moduleResolution": "node",
"rootDir": "./",
"sourceMap": true,
"allowJs": true,
"noImplicitAny": true,