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

智能推荐

vim安装python神器jedi插件_jedi安装-程序员宅基地

文章浏览阅读2.5k次。vim安装python神器jedi插件安装Vundlegit clone https://github.com/VundleVim/Vundle.vim.gi`在这里插入代码片`t ~/.vim/bundle/Vundle.vim添加配置文件~/.vimrcset nocompatible " be iMproved, requiredfiletype off " required" set the runtime pat_jedi安装

Ubuntu1804上安装Heartbeat_ubuntu 编译 heartbeat-程序员宅基地

文章浏览阅读623次。下载 Heartbeatcurl -L -O https://artifacts.elastic.co/downloads/beats/heartbeat/heartbeat-6.8.6-amd64.deb安装 Heartbeatsudo dpkg -i heartbeat-6.8.6-amd64.deb配置Heartbeat以连接到Logstash修改Heartbeat配置文件..._ubuntu 编译 heartbeat

Windows 7 Service Pack 1 and all applicable updates are required to install Python-程序员宅基地

文章浏览阅读5.5k次。目录1.Python从官网下载完后,安装时提示Setup failed2.python安装完最后一步,提示计算机中丢失api-ms-win-crt-runtime-|1-1-0.dll。尝试重新安装该程序以解决此问题1.Python从官网下载完后,安装时提示Setup failedOne or more issues caused the setup to fail.Please ..._windows 7 service pack 1 and all applicable updates are required toinstall p

转:嵌入式软件测试基本概念_嵌入式产品测试是做什么-程序员宅基地

文章浏览阅读1.2k次。嵌入式软件测试基本概念这里讨论的嵌入式软件测试是一个系统测试的概念。即将开发的软件系统(包括嵌入式操作系统和嵌入式应用软件)、硬件系统和其它相关因素(如人员的操作、数据的获取等)综合起来,对整个产品进行的全面测试。嵌入式系统的系统测试比PC系统软件测试要困难得多,主要体现如下:测试软件功能依赖不需编码的硬件功能,快速定位软硬件错误困难;强壮性测试、可知性测试很难编码实现;交叉测试平台的测试用例、测试结果上载困难;基于消息系统测试的复杂性,包括线程、任务、子系统之间的交互,并发、容错和对时间的要求;性能测试、_嵌入式产品测试是做什么

罗永浩新公司准备招人,AI写一篇代码文档只需2步,如何优雅地乱搞Python代码、一大波数学资料来袭!AI前沿论文 | ShowMeAI资讯日报-程序员宅基地

文章浏览阅读1.1w次。ShowMeAI资讯日报 2022-07-11 期,罗永浩官宣新创业公司『Thine Red Line』、Mintlify Writer 使用AI辅助生成代码文档、Lancer Python 代码混淆工具、杜克大学『数据科学数学技能』课程、『深度学习数学工程』电子书、4篇前沿论文…点击获取全部资讯......

Android Compose LazyColumn/LazyRow滚动列表控件(RecyclerView)_statusbarspadding-程序员宅基地

文章浏览阅读1k次。@Composablefun RecyclerViewDemo(){ val lists = listOf("a","b","c","d","e","f","g","h","i") Column(modifier = Modifier .fillMaxSize() .statusBarsPadding()) { Column(modifier = Modifier .statusBarsPadding() ._statusbarspadding

随便推点

拦截器有关问题(一)---preHandle执行了两次_拦截器执行两次-程序员宅基地

文章浏览阅读2.5k次。拦截器最近要写一个对于每个接口请求提前做下乱码检测,这个时候因为项目中的接口特别多,这个时候想到要写一个拦截器,在写拦截器的时候遇到了一些问题记录一下:1.spring boot 2.0+后的版本因为拦截器的WebMvcConfigurerAdapter这个抽象类已经废弃,导致不适用,不起效果了2.换成WebMvcConfigurer后,每次请求,在打印日志的时候发现preHandle总是在Controller处理之前执行一次和在Controller后又执行了一次。自定义拦截器的实现1.定义一个自_拦截器执行两次

Extjs中TreePanel树异步加载数据的步骤-程序员宅基地

文章浏览阅读1.2k次。Extjs中TreePanel树异步加载数据的步骤 1.定义根节点root:var myRoot = new Ext.tree.AsyncTreeNode({ text:"根节点", draggable:false, //根节点不可拖动 expanded:true, //根节点展开}); 2.定义数据加载器TreeLoade..._ext.tree.treepanel 异步加载挂载完成

npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\_c:\program files\nodejs\node.exe" "c:\program file-程序员宅基地

文章浏览阅读1.4w次。1 、 D:\webpack>npm install -g n npm ERR! Windows_NT 6.1.7601 npm ERR! argv “C:\Program Files\nodejs\node.exe” “C:\Program Files\nodejs\ node_modules\npm\bin\npm-cli.js” “install” “-g” “n” npm ERR!_c:\program files\nodejs\node.exe" "c:\program files\nodejs\node_modules\npm

模型实战(2)之YOLOv5 实时实例分割+训练自己数据集_模型实战(2)之yolov5 实时实例分割+训练自己数据集-程序员宅基地

文章浏览阅读3.6k次,点赞3次,收藏24次。模型实战(2)之YOLOv5 实时实例分割+训练自己数据集_模型实战(2)之yolov5 实时实例分割+训练自己数据集

基因芯片筛选差异表达基因方法比较-程序员宅基地

文章浏览阅读1.5k次。摘要: 基因芯片筛选差异表达基因方法比较单文娟, 童春发, 施季森 摘要: 使用计算机模拟数据和真实的芯片数据, 对8 种筛选差异表达基因的方法进行了比较分析, 旨在比较不同方法对基因芯片数据的筛选效果。模拟数据分析表 ...基因芯片筛选差异表达基因方法比较单文娟, 童春发, 施季森摘要: 使用计算机模拟数据和真实的..._adaboost 筛选基因的方法

HttpClient与HttpURLConnection分析_httpclientutil 替换 httpurlconnection-程序员宅基地

文章浏览阅读1k次。1.HttpClient   Android SDK中包含了HttpClient,在Android6.0版本直接删除了HttpClient类库,如果仍想使用则解决方法 是在android studio相应的module下的build.gradle中加入 android { useLibrary 'org.apache.http.legacy' }HttpClient的G_httpclientutil 替换 httpurlconnection

推荐文章

热门文章

相关标签