Remove baseURL from packages/jsonrpc#createRemoteClient

This commit is contained in:
Jerko Steiner 2019-08-30 15:01:01 +07:00
parent 19f0993088
commit 5cc20ccd8e
4 changed files with 4 additions and 8 deletions

View File

@ -80,7 +80,7 @@ describe('createActions', () => {
function getClient() { function getClient() {
const remoteClient = createRemoteClient<IService>( const remoteClient = createRemoteClient<IService>(
baseUrl, '/service', keys<IService>()) baseUrl + '/service', keys<IService>())
const client = createActions(remoteClient, 'myService') const client = createActions(remoteClient, 'myService')
const defaultState = { const defaultState = {

View File

@ -6,7 +6,6 @@ import {
TAllActions, TAllActions,
TReduxHandlers, TReduxHandlers,
} from './types' } from './types'
import {createRemoteClient} from './remote'
export function createActions<T, ActionType extends string>( export function createActions<T, ActionType extends string>(
client: TAsyncified<T>, client: TAsyncified<T>,

View File

@ -65,7 +65,7 @@ describe('remote', () => {
describe('idempotent method invocation (GET)', () => { describe('idempotent method invocation (GET)', () => {
it('creates a proxy for remote service', async () => { it('creates a proxy for remote service', async () => {
const rpc = createRemoteClient<IService>( const rpc = createRemoteClient<IService>(
baseUrl, '/myService', IServiceKeys) baseUrl + '/myService', IServiceKeys)
const result = await rpc.fetchItem({a: 10}, {b: 20}) const result = await rpc.fetchItem({a: 10}, {b: 20})
expect(result).toEqual({a: 10, b: 20}) expect(result).toEqual({a: 10, b: 20})
}) })
@ -74,7 +74,7 @@ describe('remote', () => {
describe('method invocation (POST)', () => { describe('method invocation (POST)', () => {
it('creates a proxy for remote service', async () => { it('creates a proxy for remote service', async () => {
const rpc = createRemoteClient<IService>( const rpc = createRemoteClient<IService>(
baseUrl, '/myService', IServiceKeys) baseUrl + '/myService', IServiceKeys)
const result = await rpc.add(3, 7) const result = await rpc.add(3, 7)
expect(result).toBe(3 + 7) expect(result).toBe(3 + 7)
}) })

View File

@ -8,15 +8,12 @@ export const createNumberGenerator = (val: number) => () => ++val
export const constantId = (val: string) => () => val export const constantId = (val: string) => () => val
export function createRemoteClient<T>( export function createRemoteClient<T>(
baseUrl: string,
url: string, url: string,
methods: Array<FunctionPropertyNames<T>>, methods: Array<FunctionPropertyNames<T>>,
getNextRequestId: TRequestIdGenerator<string | number> = constantId('c'), getNextRequestId: TRequestIdGenerator<string | number> = constantId('c'),
idempotentMethodRegex = IDEMPOTENT_METHOD_REGEX, idempotentMethodRegex = IDEMPOTENT_METHOD_REGEX,
) { ) {
const axios = Axios.create({ const axios = Axios.create()
baseURL: baseUrl,
})
async function createRequest( async function createRequest(
id: string | number | null, id: string | number | null,