Skip to content

Commit 2d0cce5

Browse files
committed
1. 修复 co 方法执行异常
2. 优化组件
1 parent b84c551 commit 2d0cce5

File tree

11 files changed

+179
-252
lines changed

11 files changed

+179
-252
lines changed

CHANGELOG.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# 1.0.2-alpha (2019-09-27)
2+
3+
### Bug 修复
4+
5+
- **co:** Generator 自动执行异常.
6+
7+
### 优化组件
8+
9+
- **ActiveRingChart**
10+
- **DigitalFlop**
11+
- **FullScreenContainer**
12+
- **PercentPond**
13+
- **ScrollBoard**
14+
- **ScrollBankingBoard**
15+
- **WaterLevelPond**
16+
117
# 1.0.1-alpha (2019-09-24)
218

319
### Bug 修复
@@ -6,6 +22,6 @@
622

723
# 1.0.0-alpha (2019-09-23)
824

9-
### Init
25+
### 初始化代码
1026

11-
- **Vue to React:** Convert **Vue** component to **React** component.
27+
- **Vue to React:** 转换 **Vue** 组件 为 **React** 组件.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jiaminghi/data-view-react",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "React Large screen data display component library",
55
"author": "Duan Yu <949267840@qq.com>",
66
"license": "MIT",

src/components/activeRingChart/index.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import classnames from 'classnames'
66

77
import Charts from '@jiaminghi/charts'
88

9-
import DvDigitalFlop from '../digitalFlop'
10-
119
import { deepMerge } from '@jiaminghi/charts/lib/util/index'
1210

1311
import { deepClone } from '@jiaminghi/c-render/lib/plugin/util'
1412

13+
import DigitalFlop from '../digitalFlop'
14+
1515
import { co } from '../../util'
1616

1717
import './style.less'
@@ -159,7 +159,7 @@ const ActiveRingChart = ({ config = {}, className, style }) => {
159159

160160
let option = getRingOption(mergedConfig)
161161

162-
option = {
162+
return {
163163
...option,
164164
series: option.series.reduce(
165165
(prev, serie, index) =>
@@ -178,8 +178,6 @@ const ActiveRingChart = ({ config = {}, className, style }) => {
178178
[]
179179
)
180180
}
181-
182-
return option
183181
}
184182

185183
useEffect(() => {
@@ -192,10 +190,10 @@ const ActiveRingChart = ({ config = {}, className, style }) => {
192190

193191
let activeIndex = 0
194192

195-
setState({ mergedConfig, activeIndex })
196-
197193
function * loop() {
198194
while (true) {
195+
setState({ mergedConfig, activeIndex })
196+
199197
const option = getOption(mergedConfig, activeIndex)
200198

201199
chartRef.current.setOption(option)
@@ -209,16 +207,10 @@ const ActiveRingChart = ({ config = {}, className, style }) => {
209207
if (activeIndex >= data.length) {
210208
activeIndex = 0
211209
}
212-
213-
setState(state => ({ ...state, activeIndex }))
214210
}
215211
}
216212

217-
const it = loop()
218-
219-
co(it)
220-
221-
return () => it.return()
213+
return co(loop)
222214
}, [config])
223215

224216
const classNames = useMemo(
@@ -230,7 +222,7 @@ const ActiveRingChart = ({ config = {}, className, style }) => {
230222
<div className={classNames} style={style}>
231223
<div className='active-ring-chart-container' ref={domRef} />
232224
<div className='active-ring-info'>
233-
<DvDigitalFlop config={digitalFlop} />
225+
<DigitalFlop config={digitalFlop} />
234226
<div className='active-ring-name' style={fontSize}>
235227
{ringName}
236228
</div>

src/components/digitalFlop/index.js

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,19 @@ const DigitalFlop = ({ config = {}, className, style }) => {
6969
const rendererRef = useRef(null)
7070
const graphRef = useRef(null)
7171

72-
const mergedConfigRef = useRef(null)
73-
74-
const mountedRef = useRef(true)
75-
76-
function init() {
77-
rendererRef.current = new CRender(domRef.current)
78-
79-
mergedConfigRef.current = getMergedConfig()
80-
81-
graphRef.current = getGraph()
82-
}
83-
84-
const getMergedConfig = () =>
85-
deepMerge(deepClone(defaultConfig, true), config || {})
86-
87-
function getGraph() {
88-
const { animationCurve, animationFrame } = mergedConfigRef.current
72+
function getGraph(mergedConfig) {
73+
const { animationCurve, animationFrame } = mergedConfig
8974

9075
return rendererRef.current.add({
9176
name: 'numberText',
9277
animationCurve,
9378
animationFrame,
94-
shape: getShape(),
95-
style: getStyle()
79+
shape: getShape(mergedConfig),
80+
style: getStyle(mergedConfig)
9681
})
9782
}
9883

99-
function getShape() {
100-
const { number, content, toFixed, textAlign } = mergedConfigRef.current
84+
function getShape({ number, content, toFixed, textAlign }) {
10185
const [w, h] = rendererRef.current.area
10286

10387
const position = [w / 2, h / 2]
@@ -108,22 +92,25 @@ const DigitalFlop = ({ config = {}, className, style }) => {
10892
return { number, content, toFixed, position }
10993
}
11094

111-
function getStyle() {
112-
const { style, textAlign } = mergedConfigRef.current
113-
95+
function getStyle({ style, textAlign }) {
11496
return deepMerge(style, {
11597
textAlign,
11698
textBaseline: 'middle'
11799
})
118100
}
119101

120-
useEffect(init, [])
102+
useEffect(() => {
103+
const mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {})
104+
105+
if (!rendererRef.current) {
106+
rendererRef.current = new CRender(domRef.current)
107+
108+
graphRef.current = getGraph(mergedConfig)
109+
}
121110

122-
function update() {
123-
const mergedConfig = (mergedConfigRef.current = getMergedConfig())
124111
const graph = graphRef.current
125112

126-
const shape = getShape()
113+
const shape = getShape(mergedConfig)
127114

128115
const cacheNum = graph.shape.number.length
129116
const shapeNum = shape.number.length
@@ -134,16 +121,8 @@ const DigitalFlop = ({ config = {}, className, style }) => {
134121

135122
Object.assign(graph, { animationCurve, animationFrame })
136123

137-
graph.animation('style', getStyle(), true)
124+
graph.animation('style', getStyle(mergedConfig), true)
138125
graph.animation('shape', shape)
139-
}
140-
141-
useEffect(() => {
142-
!mountedRef.current && update()
143-
144-
return () => {
145-
mountedRef.current = false
146-
}
147126
}, [config])
148127

149128
const classNames = useMemo(() => classnames('dv-digital-flop', className), [

src/components/fullScreenContainer/index.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useLayoutEffect } from 'react'
22

33
import PropTypes from 'prop-types'
44

@@ -7,31 +7,19 @@ import useAutoResize from '../../use/autoResize'
77
import './style.less'
88

99
const FullScreenContainer = ({ children, className, style }) => {
10-
const { domRef } = useAutoResize(afterAutoResizeMixinInit, () =>
11-
setAppScale(allWidth)
12-
)
13-
14-
const [{ allWidth, ready }, setState] = useState({
15-
allWidth: 0,
16-
ready: false
17-
})
10+
const { domRef } = useAutoResize()
1811

19-
function afterAutoResizeMixinInit() {
12+
useLayoutEffect(() => {
2013
const { width, height } = window.screen
2114

2215
Object.assign(domRef.current.style, {
2316
width: `${width}px`,
2417
height: `${height}px`
2518
})
2619

27-
setAppScale(width)
28-
29-
setState({ allWidth: width, ready: true })
30-
}
31-
32-
const setAppScale = allWidth =>
33-
(domRef.current.style.transform = `scale(${document.body.clientWidth /
34-
allWidth})`)
20+
domRef.current.style.transform = `scale(${document.body.clientWidth /
21+
width})`
22+
})
3523

3624
return (
3725
<div
@@ -40,7 +28,7 @@ const FullScreenContainer = ({ children, className, style }) => {
4028
style={style}
4129
ref={domRef}
4230
>
43-
{ready && children}
31+
{children}
4432
</div>
4533
)
4634
}

src/components/percentPond/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,15 @@ const PercentPond = ({ config = {}, className, style }) => {
160160
return formatter.replace('{value}', value)
161161
}, [mergedConfig])
162162

163-
function update() {
163+
useEffect(() => {
164164
const { clientWidth: width, clientHeight: height } = domRef.current
165165

166-
if (!config) {
167-
setState(state => ({ ...state, width, height }))
168-
169-
return
170-
}
171-
172166
setState({
173167
width,
174168
height,
175169
mergedConfig: deepMerge(deepClone(defaultConfig, true), config || {})
176170
})
177-
}
178-
179-
useEffect(update, [config])
171+
}, [config])
180172

181173
const classNames = useMemo(() => classnames('dv-percent-pond', className), [
182174
className

src/components/scrollBoard/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ const ScrollBoard = ({ onClick, config, className, style }) => {
201201
heights
202202
}
203203

204-
Object.assign(stateRef.current, data, { rowsData: rows })
204+
Object.assign(stateRef.current, data, { rowsData: rows, animationIndex: 0 })
205205

206206
setState(state => ({ ...state, ...data }))
207207
}
@@ -304,11 +304,7 @@ const ScrollBoard = ({ onClick, config, className, style }) => {
304304

305305
if (rowNum >= rowLength) return
306306

307-
const it = loop()
308-
309-
co(it)
310-
311-
return () => it.return()
307+
return co(loop)
312308
}, [config, domRef.current])
313309

314310
useEffect(onResize, [width, height, domRef.current])

src/components/scrollRankingBoard/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const ScrollRankingBoard = ({ config, className, style }) => {
122122

123123
heights !== undefined && Object.assign(data, { heights })
124124

125-
Object.assign(stateRef.current, data, { rowsData: rows })
125+
Object.assign(stateRef.current, data, { rowsData: rows, animationIndex: 0 })
126126

127127
setState(state => ({ ...state, ...data }))
128128
}
@@ -197,11 +197,7 @@ const ScrollRankingBoard = ({ config, className, style }) => {
197197

198198
if (rowNum >= rowLength) return
199199

200-
const it = loop()
201-
202-
co(it)
203-
204-
return () => it.return()
200+
return co(loop)
205201
}, [config, domRef.current])
206202

207203
useEffect(() => {

0 commit comments

Comments
 (0)