Skip to content

Commit

Permalink
feat(mp): 完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Aug 25, 2020
1 parent 9308bec commit f0781f7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mp/ensureInMiniProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { inMiniProgram } from '../utils'

let $mp: ReturnType<typeof inMiniProgram> | undefined

/**
* 确保当前在小程序环境并执行回调。
*
* @param cb 要执行的回调,第一个参数为小程序 API 挂载的全局变量
* @returns 返回回调的执行结果
*/
export function ensureInMiniProgram<T>(
cb: (mp: Exclude<typeof $mp, false | undefined>) => T,
): T {
Expand Down
5 changes: 5 additions & 0 deletions src/mp/navigatePageBack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ensureInMiniProgram } from './ensureInMiniProgram'

/**
* 关闭当前页面,返回上一页面或多级页面。
*
* @param delta 返回的页面数,如果 delta 大于现有页面数,则返回到首页
*/
export function navigatePageBack(delta = 1): Promise<any> {
return ensureInMiniProgram(
mp =>
Expand Down
7 changes: 7 additions & 0 deletions src/mp/navigatePageTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { createUrlQueryString, isUrl } from '../utils'
import { ensureInMiniProgram } from './ensureInMiniProgram'
import { getMiniProgramConfig } from './miniProgramConfig'

/**
* 跳转至某个页面。
*
* @param url 要跳转去的页面地址
* @param query 查询参数
* @param redirect 是否关闭当前页面后跳转
*/
export function navigatePageTo(
url: string,
query?: AnyObject,
Expand Down
6 changes: 6 additions & 0 deletions src/mp/redirectPageTo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { navigatePageTo } from './navigatePageTo'

/**
* 关闭当前页面,跳转至某个页面。
*
* @param url 要跳转去的页面地址
* @param query 查询参数
*/
export function redirectPageTo(url: string, query?: AnyObject): Promise<any> {
return navigatePageTo(url, query, true)
}
3 changes: 3 additions & 0 deletions src/mp/submit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createSubmit } from '../utils'
import { ensureInMiniProgram } from './ensureInMiniProgram'

/**
* 对提交类行为的封装。
*/
export const submit = createSubmit({
start(message) {
ensureInMiniProgram(mp => {
Expand Down

0 comments on commit f0781f7

Please sign in to comment.