Skip to content

Instantly share code, notes, and snippets.

View teyfix's full-sized avatar

Halil Teyfik teyfix

  • Istanbul, Turkey
View GitHub Profile
@teyfix
teyfix / subject.js
Last active June 20, 2021 12:39
rxjs - closing subject
const subject = new Subject();
subject.subscribe(
(value) => console.log(value),
(error) => console.error(error),
() => console.log('özne sonlandı'),
);
subject.complete();
@teyfix
teyfix / subject.js
Last active June 20, 2021 12:39
rxjs - subscribing subject
const subject = new Subject();
subject.subscribe(value => console.log(value));
subject.next('lorem');
subject.next('ipsum');
subject.next('dolor');
@teyfix
teyfix / creatingSubject.js
Last active June 20, 2021 12:39
rxjs - creating subject
const subject = new Subject();
subject.next(1);
subject.next(2);
subject.next(3);
@teyfix
teyfix / detailedSocketIO.js
Last active June 20, 2021 12:39
rxjs - detailed socket.io
import { fromEvent, Subject } from 'rxjs';
import { map, shareReplay, switchMap } from 'rxjs/operators';
import io from 'socket.io-client';
const $token = new Subject();
const $client = $token.pipe(
map((token) => {
if (null == token || '' === token) {
return {};
}
@teyfix
teyfix / mappingSource.js
Created June 20, 2021 12:37
rxjs - mapping source
subject.pipe(
map(x => x * x),
);
@teyfix
teyfix / simpleSocketIO.js
Created June 20, 2021 12:37
rxjs - simple socket.io
import { fromEvent } from 'rxjs';
import io from 'socket.io-client';
const client = io().connect();
const listen = (event: string) => fromEvent(client, event);
listen('message').subscribe((message) => console.log(message));
@teyfix
teyfix / unsubscribingSubject.js
Created June 20, 2021 12:38
rxjs - unsubscribing subject
const subject = new Subject();
const subscription = subject.subscribe(value => console.log(value));
subject.next('foo');
subject.next('bar');
subscription.unsubscribe();
@teyfix
teyfix / usingBehaviorSubject.js
Created June 20, 2021 12:38
rxjs - using behavior subject
const fibonacci = new BehaviorSubject(1);
fibonacci.next(1);
fibonacci.next(2);
fibonacci.next(3);
fibonacci.next(5);
fibonacci.next(8);
console.log(fibonacci.value);
@teyfix
teyfix / usingReplaySubject.js
Created June 20, 2021 12:38
rxjs - using replay subject
const user = new ReplaySubject(1);
authorize(session => user.next(session.user));
@teyfix
teyfix / initialState.js
Created June 21, 2021 18:51
vuex - initial state
const store = Vuex.Store({
state: {
user: null,
},
});