Revert back to context in createLocalClient
This commit is contained in:
parent
0222455cd7
commit
d2a5a35543
@ -25,7 +25,7 @@ describe('local', () => {
|
|||||||
|
|
||||||
const service = new Service()
|
const service = new Service()
|
||||||
|
|
||||||
const proxy = createLocalClient(service, () => ({userId: 1000}))
|
const proxy = createLocalClient(service, {userId: 1000})
|
||||||
|
|
||||||
describe('add', () => {
|
describe('add', () => {
|
||||||
it('should add two numbers', async () => {
|
it('should add two numbers', async () => {
|
||||||
|
|||||||
@ -7,13 +7,12 @@ import {TGetContext} from './express'
|
|||||||
* will be invoked as if it would be remotely. This helps keep the API similar
|
* will be invoked as if it would be remotely. This helps keep the API similar
|
||||||
* on the client- and server-side.
|
* on the client- and server-side.
|
||||||
*/
|
*/
|
||||||
export function createLocalClient<T, Context>(
|
export function createLocalClient<T extends {}, Context>(
|
||||||
service: T,
|
service: T,
|
||||||
getContext: () => Context,
|
context: Context,
|
||||||
): TAsyncified<ReverseContextual<T>> {
|
): TAsyncified<ReverseContextual<T>> {
|
||||||
const proxy = new Proxy({}, {
|
const proxy = new Proxy({}, {
|
||||||
get(obj, prop) {
|
get(obj, prop) {
|
||||||
const context = getContext()
|
|
||||||
return async function makeRequest(...args: any[]) {
|
return async function makeRequest(...args: any[]) {
|
||||||
const result = (service as any)[prop](context, ...args)
|
const result = (service as any)[prop](context, ...args)
|
||||||
return result
|
return result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user