源码网,源码论坛,源码之家,商业源码,游戏源码下载,discuz插件,棋牌源码下载,精品源码论坛

 找回密码
 立即注册
楼主: ttx9n

[JavaScript] vue.js源代码core scedule.js学习笔记

[复制链接]

7万

主题

861

回帖

32万

积分

论坛元老

Rank: 8Rank: 8

积分
329525
发表于 2017-7-3 16:18:45 | 显示全部楼层 |阅读模式
这篇文章主要为大家详细介绍了vue.js源代码core scedule.js的学习笔记,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

vue.js 源代码学习笔记 core scedule.js,供大家参考,具体内容如下

/* @flow */

import type Watcher from './watcher'
import config from '../config'
import { callHook } from '../instance/lifecycle'

import {
 warn,
 nextTick,
 devtools
} from '../util/index'

const queue: Array<Watcher> = []
let has: { [key: number]: ?true } = {}
let circular: { [key: number]: number } = {}
let waiting = false
let flushing = false
let index = 0

/**
 * Reset the scheduler's state.
 */
function resetSchedulerState () {
 queue.length = 0
 has = {}
 if (process.env.NODE_ENV !== 'production') {
 circular = {}
 }
 waiting = flushing = false
}

/**
 * Flush both queues and run the watchers.
 */
function flushSchedulerQueue () {
 flushing = true
 let watcher, id, vm

 // Sort queue before flush.
 // This ensures that:
 // 1. Components are updated from parent to child. (because parent is always
 // created before the child)
 // 2. A component's user watchers are run before its render watcher (because
 // user watchers are created before the render watcher)
 // 3. If a component is destroyed during a parent component's watcher run,
 // its watchers can be skipped.
 queue.sort((a, b) => a.id - b.id)

 // do not cache length because more watchers might be pushed
 // as we run existing watchers
 for (index = 0; index < queue.length; index++) {
 watcher = queue[index]
 id = watcher.id
 has[id] = null
 watcher.run()
 // in dev build, check and stop circular updates.
 if (process.env.NODE_ENV !== 'production' && has[id] != null) {
  circular[id] = (circular[id] || 0) + 1
  if (circular[id] > config._maxUpdateCount) {
  warn(
   'You may have an infinite update loop ' + (
   watcher.user
    ? `in watcher with expression "${watcher.expression}"`
    : `in a component render function.`
   ),
   watcher.vm
  )
  break
  }
 }
 }

 // reset scheduler before updated hook called
 const oldQueue = queue.slice()
 resetSchedulerState()

 // call updated hooks
 index = oldQueue.length
 while (index--) {
 watcher = oldQueue[index]
 vm = watcher.vm
 if (vm._watcher === watcher && vm._isMounted) {
  callHook(vm, 'updated')
 }
 }

 // devtool hook
 /* istanbul ignore if */
 if (devtools && config.devtools) {
 devtools.emit('flush')
 }
}

/**
 * Push a watcher into the watcher queue.
 * Jobs with duplicate IDs will be skipped unless it's
 * pushed when the queue is being flushed.
 */
export function queueWatcher (watcher: Watcher) {
 const id = watcher.id
 if (has[id] == null) {
 has[id] = true
 if (!flushing) {
  queue.push(watcher)
 } else {
  // if already flushing, splice the watcher based on its id
  // if already past its id, it will be run next immediately.
  let i = queue.length - 1
  while (i >= 0 && queue[i].id > watcher.id) {
  i--
  }
  queue.splice(Math.max(i, index) + 1, 0, watcher)
 }
 // queue the flush
 if (!waiting) {
  waiting = true
  nextTick(flushSchedulerQueue)
 }
 }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

回复

使用道具 举报

6

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
25426
发表于 2022-9-16 18:47:21 | 显示全部楼层
来看看!!!
回复 支持 反对

使用道具 举报

0

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
20242
发表于 2023-1-11 09:45:14 | 显示全部楼层
你们谁看了弄洒了可能
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

1万

积分

论坛元老

Rank: 8Rank: 8

积分
16025
发表于 2023-8-17 16:42:00 | 显示全部楼层
啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
回复 支持 反对

使用道具 举报

2

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
25798
发表于 2023-9-11 19:38:18 | 显示全部楼层
论坛有你更精彩!
回复 支持 反对

使用道具 举报

16

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
26143
发表于 2024-3-7 11:48:21 | 显示全部楼层
看看看看看看看看看看看看看看看看看看看看看看看看看看看
回复 支持 反对

使用道具 举报

2

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
25785
发表于 2024-3-19 17:00:39 | 显示全部楼层
非常vbcbvcvbvcb
回复 支持 反对

使用道具 举报

11

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
25729
发表于 2024-6-20 01:29:11 | 显示全部楼层
这个源码还可以
回复 支持 反对

使用道具 举报

2

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
24494
发表于 2024-6-21 13:16:46 | 显示全部楼层
还有什么好东西没
回复 支持 反对

使用道具 举报

7

主题

2万

回帖

2万

积分

论坛元老

Rank: 8Rank: 8

积分
25898
发表于 2024-8-4 22:47:45 | 显示全部楼层
有什么好的服务器
回复 支持 反对

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

手机版|小黑屋|网站地图|源码论坛 ( 海外版 )

GMT+8, 2025-2-11 21:05 , Processed in 0.069189 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表