-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat: add rax-componentwrapper #399
Open
cryzzchen
wants to merge
6
commits into
master
Choose a base branch
from
feature/component_wrapper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
# 1.0.0 | ||
|
||
- Add `rax-componentwrapper` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## rax-componentwrapper | ||
|
||
## 支持 | ||
阿里小程序(运行时) / 微信小程序(运行时) | ||
|
||
## 描述 | ||
在运行时小程序中,默认所有的数据更新都使用 `Page` 的 `setData` 方法。对于部分需要频繁更新数据的元素来说,可以在元素外包裹 `rax-componentwrapper` 的方式,自动将该元素转成自定义组件,当元素数据发生变化时,使用组件的 `setData`,来起到性能优化的目的。 | ||
|
||
需要注意:在阿里小程序中,需要开启基础库 2.0 构建或开启 component2 功能时,才能正常使用该组件,否则将降级使用 `Page` 的 `setData` 方法。 | ||
|
||
## 安装 | ||
|
||
``` | ||
$ npm install rax-componentwrapper --save | ||
``` | ||
|
||
## 使用 | ||
|
||
``` | ||
import ComponentWrapper from 'rax-componentwrapper'; | ||
``` | ||
## 例子 | ||
|
||
```jsx | ||
import { createElement, render, useState } from 'rax'; | ||
import DriverUniversal from 'driver-universal'; | ||
import ComponentWrapper from 'rax-componentwrapper'; | ||
import View from 'rax-view' | ||
|
||
const App = () => { | ||
const [count, setCount] = useState(1); | ||
|
||
return ( | ||
<View> | ||
<View onClick={() => setCount(count + 1)}>plus</View> | ||
<ComponentWrapper> | ||
<View>{count}</View> | ||
</ComponentWrapper> | ||
</View> | ||
); | ||
} | ||
|
||
|
||
render(<App />, document.body, { driver: DriverUniversal }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: Baisc | ||
order: 1 | ||
--- | ||
|
||
basic usage | ||
|
||
```jsx | ||
import { createElement, useState } from 'rax'; | ||
import ComponentWrapper from 'rax-componentwrapper'; | ||
import View from 'rax-view'; | ||
|
||
const App = () => { | ||
const [count, setCount] = useState(1); | ||
|
||
return ( | ||
<View> | ||
<View onClick={() => setCount(count + 1)}>plus</View> | ||
<ComponentWrapper> | ||
<View>{count}</View> | ||
</ComponentWrapper> | ||
</View> | ||
); | ||
} | ||
|
||
export default App; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "rax-componentwrapper", | ||
"version": "1.0.0", | ||
"description": "组件功能描述", | ||
"main": "lib/index.js", | ||
"module": "es/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"es", | ||
"lib" | ||
], | ||
"keywords": [ | ||
"Rax", | ||
"rax-component" | ||
], | ||
"engines": { | ||
"npm": ">=3.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/raxjs/rax-components.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/raxjs/rax-components/issues" | ||
}, | ||
"homepage": "https://github.com/raxjs/rax-components#readme", | ||
"scripts": { | ||
"build": "../../node_modules/.bin/build-scripts build --config ../../build.json --skip-demo", | ||
"start": "../../node_modules/.bin/build-scripts start --config ../../build.json", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"peerDependencies": { | ||
"rax": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@ali/build-plugin-miniapp-preview": "^1.1.0", | ||
"@alib/build-scripts": "^0.1.0", | ||
"@types/rax": "^1.0.0", | ||
"build-plugin-component": "^1.0.0", | ||
"driver-universal": "^3.1.0", | ||
"eslint": "^6.8.0", | ||
"rax": "^1.1.0", | ||
"rax-test-renderer": "^1.0.0", | ||
"rax-text": "^2.2.0", | ||
"rax-view": "^2.2.1", | ||
"stylelint": "^13.7.2", | ||
"typescript": "^3.7.3" | ||
}, | ||
"license": "BSD-3-Clause" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createElement } from 'rax'; | ||
|
||
const MyComponent = ({ children }) => { | ||
return ( | ||
<div>{children}</div> | ||
); | ||
}; | ||
|
||
export default MyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "esNext", | ||
"target": "es2015", | ||
"jsx": "preserve", | ||
"jsxFactory": "createElement", | ||
"moduleResolution": "node", | ||
"alwaysStrict": true, | ||
"sourceMap": false, | ||
"removeComments": false, | ||
"preserveConstEnums": true, | ||
"experimentalDecorators": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": false, | ||
"noImplicitAny": false, | ||
"noImplicitThis": false, | ||
"outDir": "lib", | ||
"baseUrl": "." | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"lib" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改一下 description