Skip to content

Commit

Permalink
feat: add mult-example
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Nov 7, 2019
1 parent 204b83a commit 913da30
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/apis/device/accelerometer/startAccelerometer.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sidebar_label: startAccelerometer

| Name | Type | Default | Description |
| --- | --- | :---: | --- |
| interval | `"game" | "ui" | "normal"` | `normal` | 监听加速度数据回调函数的执行频率 |
| interval | `"game" | "ui" | "normal"` | `"normal"` | 监听加速度数据回调函数的执行频率 |
| success | `Function` | | 接口调用成功的回调函数 |
| fail | `Function` | | 接口调用失败的回调函数 |
| complete | `Function` | | 接口调用结束的回调函数(调用成功、失败都会执行) |
Expand Down
17 changes: 14 additions & 3 deletions packages/taro/scripts/docs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function writeDoc (routepath: string, doc: DocEntry[]) {
]
e.documentation && md.push(e.documentation, '')
const since = tags.find(tag => tag.name === 'since')
since && md.push(`> 最低版本: ${since.text || ''}`, '')
since && md.push(`> 最低 Taro 版本: ${since.text || ''}`, '')
e.type && md.push('## 类型', '', '```tsx', e.type, '```', '')
parameters.length && md.push('## 参数', '')
parameters.map(p => {
Expand Down Expand Up @@ -149,8 +149,19 @@ export function writeDoc (routepath: string, doc: DocEntry[]) {
)
}
})
const example = tags.find(tag => tag.name === 'example')
example && md.push('## 示例代码', '', example.text || '', '')
let example_i = tags.findIndex(tag => tag.name === 'example')
let example_index = 0
do {
const example = tags[example_i]
if (example) {
example_i === 0 && md.push('## 示例代码', '')
example_index++
if ((example_i = tags.findIndex((tag, i) => example_i < i && tag.name === 'example')) > -1 || example_index > 1) {
md.push(`### 示例 ${example_index}`, '')
}
md.push((example.text || '').split('\\`@').join('@'), '')
}
} while (example_i > -1)
const supported = tags.find(tag => tag.name === 'supported')
const apis = getAPI(name, supported && supported.text)
apis.length > 0 && md.push('## API 支持度', '', ...apis, '')
Expand Down
42 changes: 21 additions & 21 deletions packages/taro/types/api/device/accelerometer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ declare namespace Taro {
}
/**
* 开始监听加速度数据。
* @supported weapp, h5, rn
* @example
```tsx
import Taro from '@tarojs/taro'
Taro.startAccelerometer({ interval: 'game' })
```
* ```tsx
* import Taro from '\`@tarojs/taro'
*
* Taro.startAccelerometer({ interval: 'game' })
* ```
* @supported weapp, h5, rn
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.startAccelerometer.html
*/
function startAccelerometer (res?: startAccelerometer.Param): Promise<any>
Expand All @@ -66,13 +66,13 @@ Taro.startAccelerometer({ interval: 'game' })
}
/**
* 停止监听加速度数据。
* @supported weapp, h5, rn
* @example
```tsx
import Taro from '@tarojs/taro'
Taro.stopAccelerometer()
```
* ```tsx
* import Taro from '\`@tarojs/taro'
*
* Taro.stopAccelerometer()
* ```
* @supported weapp, h5, rn
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.stopAccelerometer.html
*/
function stopAccelerometer (res?: stopAccelerometer.Param): Promise<any>
Expand All @@ -98,15 +98,15 @@ Taro.stopAccelerometer()
* 监听加速度数据,频率:5次/秒,接口调用后会自动开始监听,可使用 `Taro.stopAccelerometer` 停止监听。
* @supported weapp, h5, rn
* @example
```tsx
import Taro from '@tarojs/taro'
Taro.onAccelerometerChange(res => {
console.log(res.x)
console.log(res.y)
console.log(res.z)
})
```
* ```tsx
* import Taro from '\`@tarojs/taro'
*
* Taro.onAccelerometerChange(res => {
* console.log(res.x)
* console.log(res.y)
* console.log(res.z)
* })
* ```
* @see https://developers.weixin.qq.com/miniprogram/dev/api/device/accelerometer/wx.onAccelerometerChange.html
*/
function onAccelerometerChange (callback: onAccelerometerChange.Param): void
Expand Down

0 comments on commit 913da30

Please sign in to comment.