vue.js 源代码学习笔记 ----- core scedule.js-程序员宅基地

技术标签: ViewUI  javascript  

/* @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) } } }

 

这个方法主要用来保存watcher形成一个事件队列, 并且调用nextTick 执行watcher的run方法

转载于:https://www.cnblogs.com/dhsz/p/7111656.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30883777/article/details/98494185

智能推荐

【genius_platform软件平台开发】第七十二讲:linux系统驱动开发之-patchelf修改动态库链接器的方法-程序员宅基地

文章浏览阅读2.7k次。1.2 运行运行 patchelf -h 能够得到如下信息:从上面的功能描述中可以看到,patchelf 的主要功能与动态库解析器、rpath、动态库本身相关,可能在解决一些动态库链接程序执行的问题时能够用到。1.3 应用-使用自定义的动态库目录 修改 以使用中的动态库, 的翻译 这篇文章中翻译了 ld.so 动态库链接器执行的过程,其中查找动态库的步骤如下:2. 同名动态库修改应用在应用的开发过程中,在进行多部门合作开发是,大家都会使用第三方库,经常会出现同一个库,不同的版本产_patchelf

阿里云CentOS服务器的安全设置及防黑加固_阿里云怎么防止被黑-程序员宅基地

文章浏览阅读1.7k次,点赞12次,收藏19次。之前服务器有几次被攻击的事件(ssh暴力破解、恶意程序、挖矿程序等),其中一次严重事件,服务器无法登录,联系阿里云售后也无法恢复,只能重置。所以决定认真学习下安全设置,并整理成博文,以供需要的人做参考。..._阿里云怎么防止被黑

创建互斥对象-程序员宅基地

文章浏览阅读132次。program AIMQuery;uses Vcl.Forms, Winapi.Windows, UnitAIM in 'UnitAIM.pas' {Form1};{$R *.res}var hAppMutex:THandle;begin Application.Initialize; hAppMutex:=CreateMutex(n..._创建一个互斥对象句柄

win10下MYSQL的下载、安装以及配置超详解教程_mysql官网下载-程序员宅基地

文章浏览阅读10w+次,点赞79次,收藏446次。下载MYSQL 官网下载MYSQL5.7.21版本,链接地址https://www.mysql.com/downloads/。下载流程图如下: 进入官网点击Community,下载社区版。 找到MYSQL Community Server,点击下方DOWNLOAD,进入下载页面。 滑动到页面底部,官网提供了不同电脑位数(32/64位)的下载版本,我的电脑是win10-64位的,选择对应版本下载解压..._mysql官网下载

go echo 实现聊天室功能(websocket连接)_golang echo websocket-程序员宅基地

文章浏览阅读609次。最近在自学go语言,根据掌握的东西试着写一个聊天室功能,代码可能不是最精简的!效果:代码文件放的位置:服务端代码:package mainimport ( "encoding/json" "fmt" "github.com/labstack/echo" "github.com/labstack/echo/middleware" "golang.org/x/net/websocket")type Client struct { Name string //用户名称 _golang echo websocket

Win11重启后无法进入系统解决办法_win11装好后重启进不了系统-程序员宅基地

文章浏览阅读3.5k次。Win11重启后无法进入系统解决办法分享。遇到电脑不能启动问题,很多的用户都会找人来维修。其实不用这么麻烦,只要不是硬件问题,开机的时候屏幕有显示,但是是错误代码。这个情况我们是可以通过重装系统的方法来解决的,我们只需要通过u盘来安装一个新系统,就可以重新开机进入到系统中了。_win11装好后重启进不了系统

随便推点

课堂作业:web网页实验一(1)_web第四版实验1-程序员宅基地

文章浏览阅读2.2k次。需要在里编译<html><head> <title>白居易的诗</title></head><body background="2019-06-01 15'21'33.jpg"><embed src="04.忽然.mp3"><h1><font color="green"..._web第四版实验1

被废弃的 Thread.stop, Thread.suspend, Thread.resume 和Runtime.runFinalizersOnExit-程序员宅基地

文章浏览阅读158次。最近学习多线程的知识,看到API里说这些方法被废弃了,就查了一下原因Thread.stop这个方法会解除被加锁的对象的锁,因而可能造成这些对象处于不一致的状态,而且这个方法造成的ThreadDeath异常不像其他的检查期异常一样被捕获。可以使用interrupt方法代替。事实上,如果一个方法不能被interrupt,那stop方法也不会起作用。Thread.suspend, ..._runfinalizersonexit

微信小程序----修改data中的数据,页面数据不改变_微信 更改属性值后界面未刷新-程序员宅基地

文章浏览阅读7.4w次,点赞19次,收藏37次。错误原因 由于VUE等框架,我们在逻辑层修改data中的数据后,视图层(页面渲染)会跟着发生变化。当然微信小程序也是实现了相同的功能,那么出现错误的原因是什么?答案:微信小程序的setData()方法。常见赋值方式(习惯)导致的错误Page({ data: { isShow: false }, changeStatus(){ console.log(this.dat_微信 更改属性值后界面未刷新

万字长文,细说长沙银行的数字化研发管理转型之路-程序员宅基地

文章浏览阅读3.3k次,点赞2次,收藏16次。4月17日,长沙银行信息技术部陈宝生总,与Agilean 首席咨询顾问吴穹博士在2021 DevOps Days 大会上,共同作了《长沙银行数字化研发管理之路》的分享。限于大会现场分享时长..._陈宝生 长沙银行

Spark and Hadoop碎片知识点-程序员宅基地

文章浏览阅读140次。Spark and Hadoop碎片知识点合集

vue自定义指令-程序员宅基地

文章浏览阅读72次。vue自定义指令vue中除了核心功能内置的指令外,也允许注册自定义指令。有的情况下,对普通DOM元素进行底层操作,这时候就会用到自定义指令。自定义指令又分为全局的自定义指令和局部自定义指令。全局自定义指令全局注册主要是用过Vue.directive方法进行注册Vue.directive第一个参数是指令的名字(不需要写上v-前缀),第二个参数可以是对象数据。// 注册一个全局自定义指令 `v-focalize`Vue.directive('focalize', { // 当被绑定的元素插入