Skip to content

Commit 38baf08

Browse files
committed
feature: add wx.nextTick
1 parent 8a9fffb commit 38baf08

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

build.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42334,6 +42334,9 @@ const dataApi = __webpack_require__(234)
4233442334
const openApi = __webpack_require__(235)
4233542335
const _ = __webpack_require__(12)
4233642336

42337+
let nextTickQueue = []
42338+
let nextTickTimer = null
42339+
4233742340
module.exports = {
4233842341
request: _.mockAsync('request'),
4233942342

@@ -42651,6 +42654,20 @@ module.exports = {
4265142654
createIntersectionObserver(compInst, options) {
4265242655
return compInst.createIntersectionObserver(options)
4265342656
},
42657+
nextTick(func) {
42658+
nextTickQueue.push(func)
42659+
42660+
if (nextTickTimer) return
42661+
nextTickTimer = setTimeout(() => {
42662+
const funcQueue = nextTickQueue
42663+
nextTickQueue = []
42664+
nextTickTimer = null
42665+
42666+
for (const func of funcQueue) {
42667+
if (func) func()
42668+
}
42669+
}, 0)
42670+
},
4265442671
}
4265542672

4265642673

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniprogram-simulate",
3-
"version": "1.5.6",
3+
"version": "1.5.7",
44
"description": "tools for miniprogram custom component unit test",
55
"main": "index.js",
66
"types": "index.d.ts",

src/api/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const dataApi = require('./data')
55
const openApi = require('./open')
66
const _ = require('./utils')
77

8+
let nextTickQueue = []
9+
let nextTickTimer = null
10+
811
module.exports = {
912
request: _.mockAsync('request'),
1013

@@ -322,4 +325,18 @@ module.exports = {
322325
createIntersectionObserver(compInst, options) {
323326
return compInst.createIntersectionObserver(options)
324327
},
328+
nextTick(func) {
329+
nextTickQueue.push(func)
330+
331+
if (nextTickTimer) return
332+
nextTickTimer = setTimeout(() => {
333+
const funcQueue = nextTickQueue
334+
nextTickQueue = []
335+
nextTickTimer = null
336+
337+
for (const func of funcQueue) {
338+
if (func) func()
339+
}
340+
}, 0)
341+
},
325342
}

0 commit comments

Comments
 (0)