Skip to content

Commit

Permalink
fix: replay function looks not good in console when uncompressed close
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Dec 30, 2020
1 parent dc581cd commit d93176b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions __tests__/__file_snapshots__/async-call-log-all.md
Expand Up @@ -28,7 +28,7 @@ Array [
"",
Promise {},
"color: gray; font-style: italic;",
[Function anonymous],
[Function replay],
]
```

Expand Down Expand Up @@ -79,7 +79,7 @@ Array [
"",
Promise {},
"color: gray; font-style: italic;",
[Function anonymous],
[Function replay],
]
```

Expand Down
5 changes: 5 additions & 0 deletions __tests__/special-names.ts
@@ -1,3 +1,4 @@
import { replayFunction } from '../src/utils/constants'
import { withSnapshotDefault } from './utils/test'

withSnapshotDefault('AsyncCall with symbol methods', 'async-call-symbols', async (f) => {
Expand All @@ -19,3 +20,7 @@ withSnapshotDefault('AsyncCallGenerator with symbol methods', 'async-call-genera
`"Error 1: https://github.com/Jack-Works/async-call-rpc/wiki/Errors#1"`,
)
})

test('Expect replay function to be', () => {
expect(replayFunction()).toMatchInlineSnapshot(`"() => replay()"`)
})
23 changes: 17 additions & 6 deletions src/Async-Call.ts
Expand Up @@ -32,7 +32,16 @@ import { normalizeStrictOptions, normalizeLogOptions } from './utils/normalizeOp
import { AsyncCallIgnoreResponse, AsyncCallNotify, AsyncCallBatch } from './utils/internalSymbol'
import { BatchQueue } from './core/batch'
import { CallbackBasedChannel, EventBasedChannel } from './index'
import { ERROR, isArray, isFunction, isString, Promise_reject, Promise_resolve, undefined } from './utils/constants'
import {
ERROR,
isArray,
isFunction,
isString,
Promise_reject,
Promise_resolve,
replayFunction,
undefined,
} from './utils/constants'

/**
* Log options of AsyncCall
Expand Down Expand Up @@ -366,11 +375,13 @@ export function AsyncCall<OtherSideImplementedFunctions = {}>(
promise,
'color: gray; font-style: italic;',
]
if (log_requestReplay)
logArgs.push(() => {
debugger
return executor.apply(resolvedThisSideImplementationValue, args)
})
if (log_requestReplay) {
// This function will be logged to the console so it must be 1 line
// prettier-ignore
const replay = () => { debugger; return executor.apply(resolvedThisSideImplementationValue, args) }
replay.toString = replayFunction
logArgs.push(replay)
}
if (remoteStack) {
console_groupCollapsed(...logArgs)
console_log(remoteStack)
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Expand Up @@ -8,3 +8,4 @@ export const Object_setPrototypeOf = Object.setPrototypeOf
export const Promise_reject = (x: any) => Promise.reject(x)
export const Promise_resolve = <T>(x: T) => Promise.resolve(x)
export const isArray = Array.isArray
export const replayFunction = () => '() => replay()'

0 comments on commit d93176b

Please sign in to comment.