Skip to content

Commit

Permalink
release(performance-monitor): v0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Sep 26, 2023
1 parent 6bbd130 commit 516317b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
},
"performance-monitor": {
"react": true,
"version": "0.3.0",
"version": "0.4.1",
"style": true,
"icon": false,
"test": true,
Expand Down
2 changes: 1 addition & 1 deletion src/performance-monitor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "performance-monitor",
"version": "0.4.0",
"version": "0.4.1",
"description": "Realtime counter used for displaying cpu, fps metrics",
"luna": {
"react": true
Expand Down
5 changes: 3 additions & 2 deletions src/performance-monitor/react.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, useEffect, useRef } from 'react'
import PerformanceMonitor, { IOptions } from './index'
import { useNonInitialEffect } from '../share/hooks'

const LunaPerformanceMonitor: FC<IOptions> = (props) => {
const performanceMonitorRef = useRef<HTMLDivElement>(null)
Expand All @@ -17,13 +18,13 @@ const LunaPerformanceMonitor: FC<IOptions> = (props) => {
return () => performanceMonitor.current?.destroy()
}, [])

useEffect(() => {
useNonInitialEffect(() => {
if (performanceMonitor.current) {
performanceMonitor.current.setOption('theme', props.theme)
}
}, [props.theme])

useEffect(() => {
useNonInitialEffect(() => {
if (performanceMonitor.current) {
performanceMonitor.current.setOption('color', props.color)
}
Expand Down
2 changes: 1 addition & 1 deletion src/performance-monitor/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const def = story(
title="Used JS heap size"
theme={theme}
unit="MB"
color="#614d82"
// color="#614d82"
smooth={false}
data={() => {
return (performance.memory.usedJSHeapSize / 1024 / 1024).toFixed(1)
Expand Down
29 changes: 28 additions & 1 deletion src/share/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import { useState } from 'react'
import {
DependencyList,
EffectCallback,
useEffect,
useRef,
useState,
} from 'react'

export function useForceUpdate() {
const [_, setForceUpdateValue] = useState(0)

Check warning on line 10 in src/share/hooks.ts

View workflow job for this annotation

GitHub Actions / ci (12.x)

'_' is assigned a value but never used
return () => setForceUpdateValue((value) => value + 1)
}

export function useNonInitialEffect(
effect: EffectCallback,
deps?: DependencyList
) {
const initialRender = useRef(true)

useEffect(() => {
let effectReturns: any = () => {}

Check failure on line 21 in src/share/hooks.ts

View workflow job for this annotation

GitHub Actions / ci (12.x)

Unexpected empty arrow function

if (initialRender.current) {
initialRender.current = false
} else {
effectReturns = effect()
}

if (effectReturns && typeof effectReturns === 'function') {
return effectReturns
}
}, deps)
}

0 comments on commit 516317b

Please sign in to comment.