Skip to content

introducing isMuted #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ If you use Redux, read the section below on how to [Use with Redux](#use-with-re
- As a function, it receives `props` and returns a string.
- `isCollapsed` is `true` by default.
- This collapses the duration & diff logs when a component renders.
- `isMuted` is `false` by default.
- This mute the single component measure log (to be used with `startRecording` & `printRecording`)

### Record

Expand Down
2 changes: 2 additions & 0 deletions examples/src/ExampleApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ class AnotherCustomComponent extends React.Component {

const MeasuredComponent = ReactPerformance.measure({
isCollapsed: false,
isMuted: false,
getId: 'example',
Component: CustomComponent,
})

const AnotherMeasuredComponent = ReactPerformance.measure({
isCollapsed: false,
isMuted: true,
getId: 'example-2',
Component: AnotherCustomComponent,
})
Expand Down
15 changes: 10 additions & 5 deletions lib/components/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ type MeasureType = ({
getId: string | (props: Object) => string,
Component: React.ComponentType<*>,
isCollapsed?: boolean,
isMuted?: boolean,
}) => React.ComponentType<*>


const measure: MeasureType = ({ getId, Component, isCollapsed = true }) => {
const measure: MeasureType = ({ getId, Component, isCollapsed = true, isMuted = false }) => {
if (!process || !process.env || process.env.NODE_ENV !== 'development') {
return Component
}
Expand Down Expand Up @@ -51,10 +52,14 @@ const measure: MeasureType = ({ getId, Component, isCollapsed = true }) => {
prevObject: prevProps,
})
const hasChanges = !!changeDetails.length
this.groupStart(hasChanges, 'Rendered %o', componentName)
this.endTimer()
this.logChanges(changeDetails)
this.groupEnd()
if (!isMuted){
this.groupStart(hasChanges, 'Rendered %o', componentName)
this.endTimer()
this.logChanges(changeDetails)
this.groupEnd()
} else {
this.renderEndedAt = Date.now()
}
recordUpdate({ hasChanges, element: this })
}

Expand Down
4 changes: 3 additions & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type ConnectType = ({
getId: string | Object => string,
Component: React.ComponentType<*>,
isCollapsed?: boolean,
isMuted?: boolean,
}) => React.ComponentType<*>

const connect: ConnectType = ({
Expand All @@ -19,8 +20,9 @@ const connect: ConnectType = ({
getId,
Component,
isCollapsed,
isMuted,
}) => ReactRedux.connect(mapStateToProps, mapDispatchToProps)(
measure({ getId, Component, isCollapsed })
measure({ getId, Component, isCollapsed, isMuted })
)

export default connect