Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

支持注册基础组件 #324

Merged
merged 2 commits into from
Nov 21, 2019
Merged

支持注册基础组件 #324

merged 2 commits into from
Nov 21, 2019

Conversation

Darmody
Copy link
Contributor

@Darmody Darmody commented Nov 8, 2019

No description provided.

@vercel
Copy link

vercel bot commented Nov 8, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/yesmeck/remax/377cptjah
🌍 Preview: https://remax-git-feat-keep-updating.yesmeck.now.sh

@codecov
Copy link

codecov bot commented Nov 8, 2019

Codecov Report

Merging #324 into master will increase coverage by 0.86%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #324      +/-   ##
==========================================
+ Coverage   92.42%   93.29%   +0.86%     
==========================================
  Files         183      225      +42     
  Lines        2641     2817     +176     
  Branches      328      335       +7     
==========================================
+ Hits         2441     2628     +187     
+ Misses        199      188      -11     
  Partials        1        1
Impacted Files Coverage Δ
packages/remax/src/propsAlias.ts 100% <ø> (ø) ⬆️
packages/remax-cli/src/build/adapters/index.ts 100% <ø> (ø) ⬆️
...remax/src/adapters/wechat/components/RadioGroup.ts 100% <100%> (ø) ⬆️
...ges/remax/src/adapters/wechat/components/Slider.ts 100% <100%> (ø) ⬆️
packages/remax/src/createHostComponent.ts 100% <100%> (ø)
...src/adapters/alipay/components/PickerViewColumn.ts 100% <100%> (ø) ⬆️
...ges/remax/src/adapters/alipay/components/Canvas.ts 100% <100%> (ø) ⬆️
...ax/src/adapters/wechat/components/CheckboxGroup.ts 100% <100%> (ø) ⬆️
...s/remax/src/adapters/wechat/components/OpenData.ts 100% <100%> (ø) ⬆️
...kages/remax/src/adapters/wechat/components/Text.ts 100% <100%> (ø) ⬆️
... and 127 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8857729...edae15e. Read the comment docs.

@Darmody Darmody force-pushed the feat/keep-updating branch from c9a3331 to 25352fd Compare November 8, 2019 12:28
@Darmody Darmody closed this Nov 12, 2019
@yesmeck yesmeck reopened this Nov 12, 2019
@yesmeck yesmeck changed the title Feat/keep updating 支持注册组件 Nov 12, 2019
docs/guide/api.md Outdated Show resolved Hide resolved
docs/guide/component.md Outdated Show resolved Hide resolved
docs/guide/component.md Outdated Show resolved Hide resolved
@yesmeck
Copy link
Member

yesmeck commented Nov 12, 2019

API 改成:

import { createNativeComponent } from 'remax';

const Video = createNativeComponent('video');

createNativeComponent 内部给标签加上 native- 前缀。

通过这种方式创建的组件不支持设置动态属性

@Darmody
Copy link
Contributor Author

Darmody commented Nov 12, 2019

API 改成:

import { createNativeComponent } from 'remax';

const Video = createNativeComponent('video');

createNativeComponent 内部给标签加上 native- 前缀。

通过这种方式创建的组件不支持设置动态属性

这样还是同一个问题,cli不知道这个组件是用户创建的。
本质上就是我们要在编译阶段知道用户创建哪些组件,并有哪些属性

@yesmeck
Copy link
Member

yesmeck commented Nov 13, 2019

这样吧,定义一个基础组件:

// Video.js
import { createNativeComponent } from 'remax';

export const nativeComponent = true;

export const props = ['src', 'autoPlay'];

const Video = createNativeComponent('video');

export default Video;

使用:

import Video from './Video.js';

export default () => <Video src="xx" />

然后 cli 在构建的时候,跟处理自定义组件的方式类似,在构建时也去 require Video.js,看里面的 nativeComponent 标识和 props

@Darmody
Copy link
Contributor Author

Darmody commented Nov 13, 2019

*.native.js 定义为与原生相关的文件。

export const type = 'component'

识别为原生组件。

这样以后也可以扩展,定义原生 API 等等。

这样如何

@yesmeck
Copy link
Member

yesmeck commented Nov 13, 2019

API 没这个需求吧,组件这么搞主要是为了照顾构建时

@yesmeck
Copy link
Member

yesmeck commented Nov 13, 2019

.native.js

用这种后缀 ts 会有问题。

@Darmody
Copy link
Contributor Author

Darmody commented Nov 13, 2019

API 没这个需求吧,组件这么搞主要是为了照顾构建时

API不这么弄也可以。主要是 native.js。这样可以很方便得识别出来。不然通过 babel 识别很麻烦。

@Darmody
Copy link
Contributor Author

Darmody commented Nov 13, 2019

.native.js

用这种后缀 ts 会有问题。

native.js native.ts 都处理呗

@yesmeck
Copy link
Member

yesmeck commented Nov 13, 2019

不需要 babel 解析,直接去 require 就可以的。Video.js 直接会同时在运行时和构建时执行。

@Darmody
Copy link
Contributor Author

Darmody commented Nov 13, 2019

不需要 babel 解析,直接去 require 就可以的。Video.js 直接会同时在运行时和构建时执行。

怎么判断 Video.js 是原生组件,需要 require 的?

@Darmody
Copy link
Contributor Author

Darmody commented Nov 13, 2019

不然还是解析 createNativeComponent 表达式。

createNativeComponent('custom-component', ['foo', 'bar'])

要求参数都必须直接声明,不能用变量。

@Darmody Darmody force-pushed the feat/keep-updating branch 2 times, most recently from 113be4c to 72d5c1c Compare November 19, 2019 06:16
由于type定义很多本身必填的 option 其实也是不需要的,所以不如去掉
optionalPromisify,给 promisify 的 option 加个默认值
@Darmody Darmody force-pushed the feat/keep-updating branch 2 times, most recently from 16b7af0 to 0e5bf7d Compare November 20, 2019 11:17
@Darmody
Copy link
Contributor Author

Darmody commented Nov 20, 2019

这个 codesandbox ci 不发包应该是过不了了

docs/guide/component.md Outdated Show resolved Hide resolved
docs/guide/component.md Outdated Show resolved Hide resolved
@yesmeck
Copy link
Member

yesmeck commented Nov 20, 2019

remax.macro 先单独发一个吧

@yesmeck
Copy link
Member

yesmeck commented Nov 20, 2019

发个 0.0.1,不然没法测试

@Darmody
Copy link
Contributor Author

Darmody commented Nov 20, 2019

remax.macro 先单独发一个吧

这个已经发了,是 remax 还没发

@yesmeck
Copy link
Member

yesmeck commented Nov 20, 2019

那 codesandbox 应该能构建出来啊

@Darmody
Copy link
Contributor Author

Darmody commented Nov 20, 2019

那 codesandbox 应该能构建出来啊

那你进去看看为什么 codesandbox 不行

@Darmody Darmody force-pushed the feat/keep-updating branch 2 times, most recently from 1b56cf3 to 6a7c57d Compare November 20, 2019 12:54
@Darmody
Copy link
Contributor Author

Darmody commented Nov 20, 2019

那 codesandbox 应该能构建出来啊

搞定了 😈

@Darmody Darmody force-pushed the feat/keep-updating branch 3 times, most recently from b5a5e1c to f1a1e33 Compare November 20, 2019 13:34
packages/remax/macro.js Outdated Show resolved Hide resolved
@@ -0,0 +1,14 @@
function exportWrapper(module) {
Copy link
Member

Choose a reason for hiding this comment

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

这个文件没在 npm 包里

Copy link
Contributor Author

Choose a reason for hiding this comment

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

codesandbox 吗?我下下来有啊

@Darmody Darmody force-pushed the feat/keep-updating branch 2 times, most recently from 03c51ad to 14dbc57 Compare November 21, 2019 00:16
引入 remax.macro 注册 host 组件

resolve #293
@yesmeck yesmeck merged commit 4ba9c45 into master Nov 21, 2019
@yesmeck yesmeck deleted the feat/keep-updating branch November 21, 2019 06:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants