Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mpxjs/api-proxy

Package Overview
Dependencies
Maintainers
3
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mpxjs/api-proxy - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

2

package.json
{
"name": "@mpxjs/api-proxy",
"version": "1.1.2",
"version": "1.1.3",
"description": "convert miniprogram API at each end",

@@ -5,0 +5,0 @@ "module": "src/index.js",

@@ -33,4 +33,51 @@ # mpx-api-proxy

## example
#### 普通形式
```js
import mpx from '@mpxjs/core'
import apiProxy from '@mpxjs/api-proxy'
mpx.use(apiProxy, {
exclude: ['showToast'] // showToast 将不会被转换为目标平台
})
mpx.showModal({
title: '标题',
content: '这是一个弹窗',
success (res) {
if (res.cancel) {
console.log('用户点击取消')
}
}
})
```
#### 使用 promise 形式
```js
import mpx from '@mpxjs/core'
import apiProxy from '@mpxjs/api-proxy'
mpx.use(apiProxy, {
usePromise: true,
whiteList: ['showToast'] // showToast 将不能使用 promise 形式
})
wx.showActionSheet({
itemList: ['A', 'B', 'C']
})
.then(res => {
console.log(res.tapIndex)
})
.catch(err => {
console.log(err)
})
```
## Done
* ⚔ **微信 → 支付宝**
* ⚔ **百度 → 支付宝**
* ⚔ **QQ → 支付宝**

@@ -614,39 +614,29 @@ import { changeOpts, handleSuccess, getEnvObj, error, warn, noop } from '../utils'

createSelectorQuery (options = {}) {
let query = ALI_OBJ.createSelectorQuery(options)
let cbs = []
const selectorQuery = ALI_OBJ.createSelectorQuery(options)
const proxyMethods = ['boundingClientRect', 'scrollOffset']
const cbs = []
proxyMethods.forEach((name) => {
const originalMethod = selectorQuery[name]
selectorQuery[name] = function (cb = noop) {
cbs.push(cb)
return originalMethod.call(this)
}
})
if (query) {
const apiArr = ['select', 'selectAll', 'selectViewport']
const cacheExec = query.exec || noop
apiArr.forEach(key => {
const cacheKey = query[key] || noop
query[key] = dom => {
const selected = cacheKey.call(query, dom)
const cacheBoundingClientRect = selected.boundingClientRect
selected.boundingClientRect = (...args) => {
if (typeof args[0] === 'function') {
cbs.push(args[0])
// error('请将 boundingClientRect 中的回调函数放入 exec 中使用')
}
return cacheBoundingClientRect.call(selected)
}
return selected
}
})
query.exec = (fn = noop) => {
return cacheExec.call(query, res => {
cbs.forEach((cb, idx) => {
cb.call(this, res[idx])
})
cbs = []
fn.call(this, res)
const originalExec = selectorQuery.exec
selectorQuery.exec = function (originalCb = noop) {
const cb = function (results) {
results.forEach((item, index) => {
cbs[index](item)
})
originalCb(results)
}
return originalExec.call(this, cb)
}
query.in = () => query
selectorQuery.in = function () {
return this
}
return query
return selectorQuery
}

@@ -653,0 +643,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc