init (graduate from prototype)
This commit is contained in:
3
packages/scheduler/.npmignore
Normal file
3
packages/scheduler/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
__tests__/
|
||||
__mocks__/
|
||||
dist/packages
|
||||
3
packages/scheduler/README.md
Normal file
3
packages/scheduler/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# @vue/scheduler
|
||||
|
||||
> This package is published only for typing and building custom renderers. It is NOT meant to be used in applications.
|
||||
7
packages/scheduler/index.js
Normal file
7
packages/scheduler/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
module.exports = require('./dist/scheduler.cjs.prod.js')
|
||||
} else {
|
||||
module.exports = require('./dist/scheduler.cjs.js')
|
||||
}
|
||||
21
packages/scheduler/package.json
Normal file
21
packages/scheduler/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@vue/scheduler",
|
||||
"version": "3.0.0-alpha.1",
|
||||
"description": "@vue/scheduler",
|
||||
"main": "index.js",
|
||||
"module": "dist/scheduler.esm.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/vue.git"
|
||||
},
|
||||
"keywords": [
|
||||
"vue"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/vue/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/scheduler#readme"
|
||||
}
|
||||
40
packages/scheduler/src/index.ts
Normal file
40
packages/scheduler/src/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
const queue: Array<() => void> = []
|
||||
const postFlushCbs: Array<() => void> = []
|
||||
const p = Promise.resolve()
|
||||
let flushing = false
|
||||
|
||||
export function nextTick(fn: () => void) {
|
||||
p.then(fn)
|
||||
}
|
||||
|
||||
export function queueJob(job: () => void, postFlushCb?: () => void) {
|
||||
if (queue.indexOf(job) === -1) {
|
||||
if (flushing) {
|
||||
job()
|
||||
} else {
|
||||
queue.push(job)
|
||||
}
|
||||
}
|
||||
if (postFlushCb) {
|
||||
queuePostFlushCb(postFlushCb)
|
||||
}
|
||||
if (!flushing) {
|
||||
nextTick(flushJobs)
|
||||
}
|
||||
}
|
||||
|
||||
export function queuePostFlushCb(cb: () => void) {
|
||||
postFlushCbs.push(cb)
|
||||
}
|
||||
|
||||
export function flushJobs() {
|
||||
flushing = true
|
||||
let job
|
||||
while ((job = queue.shift())) {
|
||||
job()
|
||||
}
|
||||
while ((job = postFlushCbs.shift())) {
|
||||
job()
|
||||
}
|
||||
flushing = false
|
||||
}
|
||||
Reference in New Issue
Block a user