Skip to content

Commit 2780945

Browse files
authored
Log will be disabled if debug set to false (#77)
* Log will be disabled if debug set to false * Update entry
1 parent 768dd14 commit 2780945

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed [#75](https://github.com/compulim/react-scroll-to-bottom/issues/75). If `debug` is set, it will show debug in console log. If not specified, it will fallback to `NODE_ENV === 'production'`, in PR [#77](https://github.com/compulim/react-scroll-to-bottom/pull/77).
13+
1014
## [4.1.0] - 2021-01-03
1115

1216
### Added

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ export default props => (
6262
6363
## Props
6464

65-
| Name | Type | Default | Description |
66-
| ----------------------- | ---------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------ |
67-
| `checkInterval` | `number` | 150 | Recurring interval of stickiness check, in milliseconds (minimum is 17 ms) |
68-
| `className` | `string` | | Set the class name for the root element |
69-
| `debounce` | `number` | `17` | Set the debounce for tracking the `onScroll` event |
70-
| `debug` | `bool` | false | Show debug information in console |
71-
| `followButtonClassName` | `string` | | Set the class name for the follow button |
72-
| `initialScrollBehavior` | `string` | `smooth` | Set the initial scroll behavior, either `"auto"` (discrete scrolling) or `"smooth"` |
73-
| `mode` | `string` | `"bottom"` | Set it to `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top |
74-
| `nonce` | `string` | | Set the nonce for [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) |
75-
| `scroller` | `function` | `() => Infinity` | A function to determine how far should scroll when scroll is needed |
76-
| `scrollViewClassName` | `string` | | Set the class name for the container element that house all `props.children` |
65+
| Name | Type | Default | Description |
66+
| ----------------------- | ---------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
67+
| `checkInterval` | `number` | 150 | Recurring interval of stickiness check, in milliseconds (minimum is 17 ms) |
68+
| `className` | `string` | | Set the class name for the root element |
69+
| `debounce` | `number` | `17` | Set the debounce for tracking the `onScroll` event |
70+
| `debug` | `bool` | `NODE_ENV === 'development'` | Show debug information in console |
71+
| `followButtonClassName` | `string` | | Set the class name for the follow button |
72+
| `initialScrollBehavior` | `string` | `smooth` | Set the initial scroll behavior, either `"auto"` (discrete scrolling) or `"smooth"` |
73+
| `mode` | `string` | `"bottom"` | Set it to `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top |
74+
| `nonce` | `string` | | Set the nonce for [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) |
75+
| `scroller` | `function` | `() => Infinity` | A function to determine how far should scroll when scroll is needed |
76+
| `scrollViewClassName` | `string` | | Set the class name for the container element that house all `props.children` |
7777

7878
## Hooks
7979

packages/component/src/BasicScrollToBottom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ BasicScrollToBottom.defaultProps = {
7575
children: undefined,
7676
className: undefined,
7777
debounce: undefined,
78-
debug: false,
78+
debug: undefined,
7979
followButtonClassName: undefined,
8080
initialScrollBehavior: 'smooth',
8181
mode: undefined,

packages/component/src/ScrollToBottom/Composer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ const Composer = ({
5353
checkInterval,
5454
children,
5555
debounce,
56-
debug: forceDebug,
56+
debug: debugFromProp,
5757
initialScrollBehavior,
5858
mode,
5959
nonce,
6060
scroller
6161
}) => {
62-
const debug = useMemo(() => createDebug(`<ScrollToBottom>`, { force: forceDebug }), [forceDebug]);
62+
const debug = useMemo(() => createDebug(`<ScrollToBottom>`, { force: debugFromProp }), [debugFromProp]);
6363

6464
mode = mode === MODE_TOP ? MODE_TOP : MODE_BOTTOM;
6565

@@ -580,7 +580,7 @@ Composer.defaultProps = {
580580
checkInterval: 100,
581581
children: undefined,
582582
debounce: 17,
583-
debug: false,
583+
debug: undefined,
584584
initialScrollBehavior: 'smooth',
585585
mode: undefined,
586586
nonce: undefined,

packages/component/src/utils/debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function format(category, arg0, ...args) {
99
return [`%c${category}%c ${arg0}`, ...styleConsole('green', 'white'), ...args];
1010
}
1111

12-
export default function debug(category, { force = false } = {}) {
13-
if (!force && NODE_ENV !== 'development') {
12+
export default function debug(category, { force = NODE_ENV === 'development' } = {}) {
13+
if (!force) {
1414
return () => 0;
1515
}
1616

0 commit comments

Comments
 (0)