diff --git a/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts b/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts index 42eb84e9374..8587277ee71 100644 --- a/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts +++ b/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts @@ -14,13 +14,12 @@ * limitations under the License. */ +import type { Observable } from 'rxjs'; +import type { IMessageProtocol } from '../rpc.service'; import { awaitTime } from '@univerjs/core'; import { of, Subject } from 'rxjs'; import { beforeEach, describe, expect, it } from 'vitest'; - -import type { Observable } from 'rxjs'; import { ChannelClient, ChannelServer, fromModule, toModule } from '../rpc.service'; -import type { IMessageProtocol } from '../rpc.service'; describe('Test ChannelClient & ChannelServer', () => { let clientProtocol: TestMessageProtocolForClient; diff --git a/packages/rpc/src/services/rpc/rpc.service.ts b/packages/rpc/src/services/rpc/rpc.service.ts index 43aa4066475..70ac7337660 100644 --- a/packages/rpc/src/services/rpc/rpc.service.ts +++ b/packages/rpc/src/services/rpc/rpc.service.ts @@ -36,8 +36,8 @@ export interface IMessageProtocol { * event sources are usually provided by the same service or controller. */ export interface IChannel { - call(method: string, ...args: any[]): Promise; - subscribe(event: string, ...args: any[]): Observable; + call(method: string, args?: any): Promise; + subscribe(event: string, args?: any): Observable; } /** @@ -55,7 +55,7 @@ export function fromModule(module: unknown): IChannel { // const observables = new Map>(); return new (class implements IChannel { - call(method: string, args: any[]): Promise { + call(method: string, args?: any): Promise { const target = handler[method]; if (typeof target === 'function') { let res = args ? target.apply(handler, args) : target.call(handler); @@ -68,10 +68,10 @@ export function fromModule(module: unknown): IChannel { throw new Error(`[RPC]: method not found for ${method}!`); } - subscribe(eventMethod: string, ...args: any[]): Observable { + subscribe(eventMethod: string, args?: any): Observable { const target = handler[eventMethod]; if (typeof target === 'function') { - const res = args ? target.call(handler, ...args) : target.call(handler); + const res = args ? target.apply(handler, args) : target.call(handler); if (!isObservable(res)) { return of(res); } @@ -102,11 +102,11 @@ export function toModule(channel: IChannel): T { return function (...args: any[]) { const isObservable = propertyIsEventSource(propKey); if (isObservable) { - const observable = channel.subscribe(propKey, ...args); + const observable = channel.subscribe(propKey, args); return observable; } - return channel.call(propKey, ...args); + return channel.call(propKey, args); }; }, }); @@ -206,7 +206,7 @@ export class ChannelClient extends RxDisposable implements IChannelClient { const self = this; return { - call(method: string, ...args: any[]) { + call(method: string, args?: any) { if (self._disposed) { return Promise.reject(); } @@ -232,7 +232,7 @@ export class ChannelClient extends RxDisposable implements IChannelClient { ); } - private async _remoteCall(channelName: string, method: string, args: any[]): Promise { + private async _remoteCall(channelName: string, method: string, args?: any): Promise { await this._whenReady(); const sequence = ++this._lastRequestCounter; @@ -265,7 +265,7 @@ export class ChannelClient extends RxDisposable implements IChannelClient { }); } - private _remoteSubscribe(channelName: string, method: string, args: any[]): Observable { + private _remoteSubscribe(channelName: string, method: string, args?: any): Observable { return new Observable((subscriber) => { let sequence: number = -1; this._whenReady().then(() => {