많은 사랑이 필요합니다. 방금 RxJS-Socket.io를 0.3.7로 업데이트했습니다.

일을 위해 긴 1년을 개발한 후 마침내 일과 .. 사이에 약간의 휴식을 취할 수 있었습니다. 음, 진지하게 말하겠습니다. 할 일이 별로 없고 게임이 지루한 일이 되었습니다. 시간을 쏟을 수 있었습니다. 죽음에서 내 작은 프로젝트를 가져와.

재도입RxJs-Socket.io ; 우리의 삶을 더 쉽게 만들어주는 socket.io 및 RxJ 주변의 간단한 래퍼 - 그 이면에 있는 생각은 내가 모든 이벤트와 콜백, 특수한 경우를 추적하고 공유하는 것을 싫어한다는 것입니다. 그리고.. 이제 그럴 필요가 없습니다! :디

특정 이벤트에 대한 전역 스트림을 갖고 있는 것처럼 생각하면 간단히 가져오고 파이프한 다음 필요하지 않을 때 구독 및 구독 취소할 수 있습니다. 그리고 당신이 정말로 원한다면, 당신은 그것을 죽일 수 있습니다.


연결



npm
https://www.npmjs.com/package/rxjs-socket.io

읽어보기
https://gitlab.com/moshmage/rxjs-socket.io/-/blob/master/README.md

문서
https://moshmage.gitlab.io/rxjs-socket.io/modules/_index_.html



// events.ts
import {IO, ioEvent} from 'rxjs-socket.io';

export const socket = new IO();

const helloWorld = new ioEvent<{text: string}>('hello-world');
const showoff = new ioEvent<any>('name', !!uniqueEvent, +count, initialState);


export const IOEvents = {helloWorld, ping};


// some-other-file.ts
import {IOEvents, socket} from 'events.ts';

const helloStream$ = IOEvents.helloWorld.event$;

helloStream$.pipe(
                filter(event => event.text === 'hello world'),
                take(1))
            .subscribe(({text}) => {
                console.log('text should be "hello world"', text);
                // make it dead -- we only take 1, but this event is still hooked, if you make it dead you make it silent for every other subscription
                IOEvents.helloWorld.unhook()
            });


socket.listenToEvent(IOEvent.helloWorld);

const [you$, can$, also$] = socket.listen(['do', 'this', 'if-you-want']);

you$.subscribe(data => console.log('you$ stream', data))

socket.connect('protocol://address:port');

// server.ts

//...
socket.emit('hello-world', {text: 'hello world'});

좋은 웹페이지 즐겨찾기