Skip to content
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

fix(types): fix the types of the entries and plugins #951

Merged
merged 1 commit into from Jul 9, 2020

Conversation

fjc0k
Copy link
Contributor

@fjc0k fjc0k commented Jul 9, 2020

Checklist
  • commit message follows commit guidelines
Description of change
  • 修复对入口文件的类型定义方式,实际使用发现,直接 declare module '***.js' {} 是无法给指定文件定义类型的,因此,创建了一个 patch-types.js 的脚本直接生成入口文件的类型定义文件;
  • 因为某些插件需要手动引入使用,因此添加了各插件的类型定义文件,方法同上。

实际效果:

image
image

Copy link

@tests-checker tests-checker bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add tests to make sure this change works as expected?

@zengyue
Copy link
Contributor

zengyue commented Jul 9, 2020

你是在什么情况下需要给这几个指定文件定义类型?

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

@zengyue 小程序里,因为小程序开发模式下有 2M 限制,只好引入 min 版本,而目前 min 版本没有类型定义:

image

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

@zengyue 另外,老哥,你使用的 vscode 吗?是的话可以安装个 prettier 插件,然后开启仅项目存在 .prettierrc 之类的配置文件才生效的选项,这样咱们的风格能统一一点,或者需要我在 pre-commit 时加上 prettier 嘛。
image

@zengyue
Copy link
Contributor

zengyue commented Jul 9, 2020

@zengyue 另外,老哥,你使用的 vscode 吗?是的话可以安装个 prettier 插件,然后开启仅项目存在 .prettierrc 之类的配置文件才生效的选项,这样咱们的风格能统一一点,或者需要我在 pre-commit 时加上 prettier 嘛。
image

这个比较难统一,因为每个人用的ide可能都不太一样

@zengyue
Copy link
Contributor

zengyue commented Jul 9, 2020

@zengyue 小程序里,因为小程序开发模式下有 2M 限制,只好引入 min 版本,而目前 min 版本没有类型定义:

这个是单包2m, 还是所有总和2M ?

@zengyue
Copy link
Contributor

zengyue commented Jul 9, 2020

另外,你是直接用的F2, 没有用wx-f2 和 my-f2 ?

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

@zengyue 小程序里,因为小程序开发模式下有 2M 限制,只好引入 min 版本,而目前 min 版本没有类型定义:

这个是单包2m, 还是所有总和2M ?

微信小程序总的项目体积 2M 以内才能预览,使用 Taro 的话如果在开发时开启压缩,又太慢了,当然也可以通过 alias 指向 min 版本,不过给 min 版本加上类型直接引用也没啥不妥。

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

另外,你是直接用的F2, 没有用wx-f2 和 my-f2 ?

你们要是提供个 taro-f2 我可能还能直接使用 😂

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

我本地搞的 Taro-f2。。可以参考:

import _ from './Chart.less'
import F2 from '@antv/f2/dist/f2.min.js'
import React, { useCallback, useEffect, useMemo, useRef } from 'react'
import { Canvas } from '@tarojs/components'
import { CanvasProps } from '@tarojs/components/types/Canvas'
import { createSelectorQuery, getSystemInfoSync } from '@tarojs/taro'
import { wait } from 'vtils'

export interface ChartProps<TRecord extends F2.DataRecord> extends CanvasProps {
  config: (chart: F2.Chart<TRecord>) => any
}

let counter = 1

export function Chart<TRecord extends F2.DataRecord>(
  props: ChartProps<TRecord>,
) {
  const id = useMemo(() => `chart_${counter++}`, [])

  const canvasElRef = useRef<any>()

  useEffect(() => {
    wait(0).then(() => {
      createSelectorQuery()
        .select(`#${id}`)
        .fields({
          node: true,
          size: true,
        })
        .exec(res => {
          const { node, width, height } = res[0]
          const context = node.getContext('2d')
          const pixelRatio = getSystemInfoSync().pixelRatio

          // 高清设置
          node.width = width * pixelRatio
          node.height = height * pixelRatio

          const chart = new F2.Chart<TRecord>({
            context,
            width,
            height,
            pixelRatio,
          })
          props.config(chart)
          chart.render()
          canvasElRef.current = chart.get('el')
        })
    })
  }, [])

  const handleTouchStart = useCallback((e: any) => {
    canvasElRef.current?.dispatchEvent('touchstart', e)
  }, [])

  const handleTouchMove = useCallback((e: any) => {
    canvasElRef.current?.dispatchEvent('touchmove', e)
  }, [])

  const handleTouchEnd = useCallback((e: any) => {
    canvasElRef.current?.dispatchEvent('touchend', e)
  }, [])

  return (
    <Canvas
      {...props}
      type='2d'
      id={id}
      className={`${_.chart} ${props.className || ''}`}
      onTouchStart={handleTouchStart}
      onTouchMove={handleTouchMove}
      onTouchEnd={handleTouchEnd}
    />
  )
}

@zengyue
Copy link
Contributor

zengyue commented Jul 9, 2020

另外,你是直接用的F2, 没有用wx-f2 和 my-f2 ?

你们要是提供个 taro-f2 我可能还能直接使用 😂

没,只是确认下 😃

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

@zengyue 另外,老哥,你使用的 vscode 吗?是的话可以安装个 prettier 插件,然后开启仅项目存在 .prettierrc 之类的配置文件才生效的选项,这样咱们的风格能统一一点,或者需要我在 pre-commit 时加上 prettier 嘛。
image

这个比较难统一,因为每个人用的ide可能都不太一样

那我可以把它加在这儿吗
image

@zengyue
Copy link
Contributor

zengyue commented Jul 9, 2020

@zengyue 另外,老哥,你使用的 vscode 吗?是的话可以安装个 prettier 插件,然后开启仅项目存在 .prettierrc 之类的配置文件才生效的选项,这样咱们的风格能统一一点,或者需要我在 pre-commit 时加上 prettier 嘛。
image

这个比较难统一,因为每个人用的ide可能都不太一样

那我可以把它加在这儿吗
image

这个可以的

@fjc0k
Copy link
Contributor Author

fjc0k commented Jul 9, 2020

这个可以的

ok, 那我晚点提个 pr

@zengyue zengyue merged commit 23a71c1 into antvis:master Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants