init (graduate from prototype)

This commit is contained in:
Evan You
2018-09-19 11:35:38 -04:00
commit 3401f6b460
63 changed files with 8372 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
__tests__/
__mocks__/
dist/packages

View 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.

View 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')
}

View 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"
}

View 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
}