| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var Template = require("./Template"); | 
					
						
							|  |  |  | var BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | 
					
						
							|  |  |  | var ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependency"); | 
					
						
							|  |  |  | var ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency"); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | var RawSource = require("webpack-core/lib/RawSource"); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | var ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							|  |  |  | var NullFactory = require("./NullFactory"); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | function HotModuleReplacementPlugin() { | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = HotModuleReplacementPlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HotModuleReplacementPlugin.prototype.apply = function(compiler) { | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 	var hotUpdateChunkFilename = compiler.options.output.hotUpdateChunkFilename; | 
					
						
							|  |  |  | 	var hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	compiler.plugin("compilation", function(compilation, params) { | 
					
						
							| 
									
										
										
										
											2014-06-03 06:14:46 +08:00
										 |  |  | 		var hotUpdateChunkTemplate = compilation.hotUpdateChunkTemplate; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		if(!hotUpdateChunkTemplate) return; | 
					
						
							| 
									
										
										
										
											2013-06-20 18:04:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		var normalModuleFactory = params.normalModuleFactory; | 
					
						
							|  |  |  | 		var contextModuleFactory = params.contextModuleFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 		compilation.dependencyFactories.set(ConstDependency, new NullFactory()); | 
					
						
							|  |  |  | 		compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		compilation.dependencyFactories.set(ModuleHotAcceptDependency, normalModuleFactory); | 
					
						
							|  |  |  | 		compilation.dependencyTemplates.set(ModuleHotAcceptDependency, new ModuleHotAcceptDependency.Template()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compilation.dependencyFactories.set(ModuleHotDeclineDependency, normalModuleFactory); | 
					
						
							|  |  |  | 		compilation.dependencyTemplates.set(ModuleHotDeclineDependency, new ModuleHotDeclineDependency.Template()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compilation.plugin("record", function(compilation, records) { | 
					
						
							|  |  |  | 			if(records.hash === this.hash) return; | 
					
						
							|  |  |  | 			records.hash = compilation.hash; | 
					
						
							|  |  |  | 			records.moduleHashs = {}; | 
					
						
							|  |  |  | 			this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 				var identifier = module.identifier(); | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 				var hash = require("crypto").createHash("md5"); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				module.updateHash(hash); | 
					
						
							|  |  |  | 				records.moduleHashs[identifier] = hash.digest("hex"); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			records.chunkHashs = {}; | 
					
						
							|  |  |  | 			this.chunks.forEach(function(chunk) { | 
					
						
							|  |  |  | 				records.chunkHashs[chunk.id] = chunk.hash; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			records.chunkModuleIds = {}; | 
					
						
							|  |  |  | 			this.chunks.forEach(function(chunk) { | 
					
						
							|  |  |  | 				records.chunkModuleIds[chunk.id] = chunk.modules.map(function(m) { return m.id; }); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 		compilation.plugin("after-hash", function() { | 
					
						
							|  |  |  | 			var records = this.records; | 
					
						
							|  |  |  | 			if(!records) return; | 
					
						
							| 
									
										
										
										
											2013-07-08 14:12:48 +08:00
										 |  |  | 			var lastHash = records.hash || "x"; | 
					
						
							|  |  |  | 			var preHash = records.preHash || "x"; | 
					
						
							|  |  |  | 			var prepreHash = records.prepreHash || "x"; | 
					
						
							| 
									
										
										
										
											2013-07-05 20:17:19 +08:00
										 |  |  | 			if(preHash === this.hash) { | 
					
						
							| 
									
										
										
										
											2013-07-08 14:12:48 +08:00
										 |  |  | 				this.modifyHash(prepreHash); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 			records.prepreHash = records.hash || "x"; | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			records.preHash = this.hash; | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 			this.modifyHash(records.prepreHash); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		compilation.plugin("additional-chunk-assets", function() { | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			var records = this.records; | 
					
						
							|  |  |  | 			if(records.hash === this.hash) return; | 
					
						
							|  |  |  | 			if(!records.moduleHashs || !records.chunkHashs || !records.chunkModuleIds) return; | 
					
						
							|  |  |  | 			var moduleHashs = {}; | 
					
						
							|  |  |  | 			this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 				var identifier = module.identifier(); | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 				var hash = require("crypto").createHash("md5"); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				module.updateHash(hash); | 
					
						
							|  |  |  | 				hash = hash.digest("hex"); | 
					
						
							|  |  |  | 				module.hotUpdate = records.moduleHashs[identifier] !== hash; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			var hotUpdateMainContent = { | 
					
						
							|  |  |  | 				h: this.hash, | 
					
						
							|  |  |  | 				c: [] | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			Object.keys(records.chunkHashs).forEach(function(chunkId) { | 
					
						
							|  |  |  | 				chunkId = +chunkId; | 
					
						
							|  |  |  | 				var currentChunk = this.chunks.filter(function(chunk) { | 
					
						
							|  |  |  | 					return chunk.id === chunkId; | 
					
						
							|  |  |  | 				})[0]; | 
					
						
							|  |  |  | 				if(currentChunk) { | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 					var newModules = currentChunk.modules.filter(function(module) { | 
					
						
							|  |  |  | 						return module.hotUpdate; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 					if(newModules.length > 0) { | 
					
						
							|  |  |  | 						var source = hotUpdateChunkTemplate.render(chunkId, newModules, this.hash, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							| 
									
										
										
										
											2014-08-22 19:51:24 +08:00
										 |  |  | 						var filename = this.getPath(hotUpdateChunkFilename, { | 
					
						
							|  |  |  | 							hash: records.hash, | 
					
						
							|  |  |  | 							chunk: currentChunk | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2013-12-13 15:55:13 +08:00
										 |  |  | 						this.additionalChunkAssets.push(filename); | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 						this.assets[filename] = source; | 
					
						
							|  |  |  | 						hotUpdateMainContent.c.push(chunkId); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 						currentChunk.files.push(filename); | 
					
						
							|  |  |  | 						this.applyPlugins("chunk-asset", currentChunk, filename); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}, this); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			var source = new RawSource(JSON.stringify(hotUpdateMainContent)); | 
					
						
							| 
									
										
										
										
											2014-08-22 19:51:24 +08:00
										 |  |  | 			var filename = this.getPath(hotUpdateMainFilename, { | 
					
						
							|  |  |  | 				hash: records.hash | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			this.assets[filename] = source; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("hash", function(hash) { | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			hash.update("HotMainTemplateDecorator"); | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("module-require", function(_, chunk, hash, varModuleId) { | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			return "hotCreateRequire(" + varModuleId + ")"; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("require-extensions", function(source, chunk, hash) { | 
					
						
							|  |  |  | 			var buf = [source]; | 
					
						
							|  |  |  | 			buf.push(""); | 
					
						
							|  |  |  | 			buf.push("// __webpack_hash__"); | 
					
						
							|  |  |  | 			buf.push(this.requireFn + ".h = function() { return hotCurrentHash; };"); | 
					
						
							|  |  |  | 			return this.asString(buf); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("bootstrap", function(source, chunk, hash) { | 
					
						
							|  |  |  | 			source = this.applyPluginsWaterfall("hot-bootstrap", source, chunk, hash); | 
					
						
							|  |  |  | 			return this.asString([ | 
					
						
							|  |  |  | 				source, | 
					
						
							|  |  |  | 				"", | 
					
						
							|  |  |  | 				hotInitCode | 
					
						
							|  |  |  | 					.replace(/\$require\$/g, this.requireFn) | 
					
						
							|  |  |  | 					.replace(/\$hash\$/g, JSON.stringify(hash)) | 
					
						
							| 
									
										
										
										
											2014-07-24 23:53:46 +08:00
										 |  |  | 					.replace(/\/\*foreachInstalledChunks\*\//g, chunk.chunks.length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = " + chunk.id +  ";") | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 			]); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("global-hash", function() { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-04-20 03:35:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-03 15:02:02 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("current-hash", function(_, length) { | 
					
						
							|  |  |  | 			if(isFinite(length)) | 
					
						
							|  |  |  | 				return "hotCurrentHash.substr(0, " + length + ")"; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				return "hotCurrentHash"; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 		compilation.mainTemplate.plugin("module-obj", function(source, chunk, hash, varModuleId) { | 
					
						
							|  |  |  | 			return this.asString([ | 
					
						
							|  |  |  | 				source + ",", | 
					
						
							| 
									
										
										
										
											2014-08-13 20:53:23 +08:00
										 |  |  | 				"hot: hotCreateModule(" + varModuleId + "),", | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 				"parents: hotCurrentParents,", | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 				"children: []" | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-08-25 15:50:26 +08:00
										 |  |  | 	compiler.parser.plugin("expression __webpack_hash__", function(expr) { | 
					
						
							|  |  |  | 		var dep = new ConstDependency("__webpack_require__.h()", expr.range); | 
					
						
							|  |  |  | 		dep.loc = expr.loc; | 
					
						
							|  |  |  | 		this.state.current.addDependency(dep); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	compiler.parser.plugin("evaluate typeof __webpack_hash__", function(expr) { | 
					
						
							|  |  |  | 		return new BasicEvaluatedExpression().setString("string").setRange(expr.range); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	compiler.parser.plugin("evaluate Identifier module.hot", function(expr) { | 
					
						
							| 
									
										
										
										
											2013-06-20 18:04:31 +08:00
										 |  |  | 		return new BasicEvaluatedExpression() | 
					
						
							| 
									
										
										
										
											2014-06-03 06:14:46 +08:00
										 |  |  | 			.setBoolean(!!this.state.compilation.hotUpdateChunkTemplate) | 
					
						
							| 
									
										
										
										
											2013-06-20 18:04:31 +08:00
										 |  |  | 			.setRange(expr.range); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 	compiler.parser.plugin("call module.hot.accept", function(expr) { | 
					
						
							| 
									
										
										
										
											2014-06-03 06:14:46 +08:00
										 |  |  | 		if(!this.state.compilation.hotUpdateChunkTemplate) return false; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		if(expr.arguments.length > 1) { | 
					
						
							| 
									
										
										
										
											2014-09-14 08:33:35 +08:00
										 |  |  | 			var arg = this.evaluateExpression(expr.arguments[0]); | 
					
						
							| 
									
										
										
										
											2014-09-16 00:04:04 +08:00
										 |  |  | 			var params = []; | 
					
						
							|  |  |  | 			if(arg.isString()) { | 
					
						
							|  |  |  | 				params = [arg]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(arg.isArray()){ | 
					
						
							| 
									
										
										
										
											2014-09-18 07:08:18 +08:00
										 |  |  | 				params = arg.items.filter(function(param) {  | 
					
						
							|  |  |  | 					return param.isString(); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-09-16 00:04:04 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			params.forEach(function(param){ | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				var dep = new ModuleHotAcceptDependency(param.string, param.range); | 
					
						
							|  |  |  | 				dep.optional = true; | 
					
						
							|  |  |  | 				this.state.module.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2014-09-16 00:04:04 +08:00
										 |  |  | 			}.bind(this)); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	compiler.parser.plugin("call module.hot.decline", function(expr) { | 
					
						
							| 
									
										
										
										
											2014-06-03 06:14:46 +08:00
										 |  |  | 		if(!this.state.compilation.hotUpdateChunkTemplate) return false; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		if(expr.arguments.length > 1) { | 
					
						
							|  |  |  | 			var param = this.evaluateExpression(expr.arguments[0]); | 
					
						
							|  |  |  | 			if(param.isString()) { | 
					
						
							|  |  |  | 				var dep = new ModuleHotDeclineDependency(param.string, param.range); | 
					
						
							|  |  |  | 				dep.optional = true; | 
					
						
							|  |  |  | 				this.state.module.addDependency(dep); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	compiler.parser.plugin("expression module.hot", function() { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | var hotInitCode = Template.getFunctionContent(function() { | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	var hotApplyOnUpdate = true; | 
					
						
							|  |  |  | 	var hotCurrentHash = $hash$; | 
					
						
							| 
									
										
										
										
											2013-06-20 04:31:12 +08:00
										 |  |  | 	var hotCurrentModuleData = {}; | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 	var hotCurrentParents = []; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	function hotCreateRequire(moduleId) { | 
					
						
							|  |  |  | 		var me = installedModules[moduleId]; | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 		if(!me) return $require$; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		var fn = function(request) { | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 			if(me.hot.active) { | 
					
						
							|  |  |  | 				if(installedModules[request]) { | 
					
						
							|  |  |  | 					if(installedModules[request].parents.indexOf(moduleId) < 0) | 
					
						
							|  |  |  | 						installedModules[request].parents.push(moduleId); | 
					
						
							|  |  |  | 					if(me.children.indexOf(request) < 0) | 
					
						
							|  |  |  | 						me.children.push(request); | 
					
						
							|  |  |  | 				} else hotCurrentParents = [moduleId]; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId); | 
					
						
							|  |  |  | 				hotCurrentParents = []; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			return $require$(request); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 		for(var name in $require$) { | 
					
						
							|  |  |  | 			if(Object.prototype.hasOwnProperty.call($require$, name)) { | 
					
						
							|  |  |  | 				fn[name] = $require$[name]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		fn.e = function(chunkId, callback) { | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 			if(hotStatus === "ready") | 
					
						
							|  |  |  | 				hotSetStatus("prepare"); | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 			hotChunksLoading++; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			$require$.e(chunkId, function() { | 
					
						
							| 
									
										
										
										
											2013-06-20 04:31:12 +08:00
										 |  |  | 				try { | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 					callback.call(null, fn); | 
					
						
							| 
									
										
										
										
											2013-10-11 17:09:42 +08:00
										 |  |  | 				} finally { | 
					
						
							| 
									
										
										
										
											2013-06-20 04:31:12 +08:00
										 |  |  | 					finishChunkLoading(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				function finishChunkLoading() { | 
					
						
							|  |  |  | 					hotChunksLoading--; | 
					
						
							|  |  |  | 					if(hotStatus === "prepare") { | 
					
						
							|  |  |  | 						if(!hotWaitingFilesMap[chunkId]) { | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 							hotEnsureUpdateChunk(chunkId); | 
					
						
							| 
									
										
										
										
											2013-06-20 04:31:12 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 						if(hotChunksLoading === 0 && hotWaitingFiles === 0) { | 
					
						
							|  |  |  | 							hotUpdateDownloaded(); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return fn; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function hotCreateModule(moduleId) { | 
					
						
							|  |  |  | 		var hot = { | 
					
						
							|  |  |  | 			// private stuff
 | 
					
						
							|  |  |  | 			_acceptedDependencies: {}, | 
					
						
							|  |  |  | 			_declinedDependencies: {}, | 
					
						
							|  |  |  | 			_selfAccepted: false, | 
					
						
							|  |  |  | 			_selfDeclined: false, | 
					
						
							|  |  |  | 			_disposeHandlers: [], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Module API
 | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 			active: true, | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			accept: function(dep, callback) { | 
					
						
							|  |  |  | 				if(typeof dep === "undefined") | 
					
						
							|  |  |  | 					hot._selfAccepted = true; | 
					
						
							| 
									
										
										
										
											2014-08-14 16:03:51 +08:00
										 |  |  | 				else if(typeof dep === "function") | 
					
						
							|  |  |  | 					hot._selfAccepted = dep; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				else if(typeof dep === "number") | 
					
						
							|  |  |  | 					hot._acceptedDependencies[dep] = callback; | 
					
						
							|  |  |  | 				else for(var i = 0; i < dep.length; i++) | 
					
						
							|  |  |  | 					hot._acceptedDependencies[dep[i]] = callback; | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			decline: function(dep) { | 
					
						
							|  |  |  | 				if(typeof dep === "undefined") | 
					
						
							|  |  |  | 					hot._selfDeclined = true; | 
					
						
							|  |  |  | 				else if(typeof dep === "number") | 
					
						
							|  |  |  | 					hot._declinedDependencies[dep] = true; | 
					
						
							|  |  |  | 				else for(var i = 0; i < dep.length; i++) | 
					
						
							|  |  |  | 					hot._declinedDependencies[dep[i]] = true; | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			dispose: function(callback) { | 
					
						
							|  |  |  | 				hot._disposeHandlers.push(callback); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			addDisposeHandler: function(callback) { | 
					
						
							|  |  |  | 				hot._disposeHandlers.push(callback); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			removeDisposeHandler: function(callback) { | 
					
						
							|  |  |  | 				var idx = hot._disposeHandlers.indexOf(callback); | 
					
						
							|  |  |  | 				if(idx >= 0) hot._disposeHandlers.splice(idx, 1); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Management API
 | 
					
						
							|  |  |  | 			check: hotCheck, | 
					
						
							|  |  |  | 			apply: hotApply, | 
					
						
							|  |  |  | 			status: function(l) { | 
					
						
							|  |  |  | 				if(!l) return hotStatus; | 
					
						
							|  |  |  | 				hotStatusHandlers.push(l); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			addStatusHandler: function(l) { | 
					
						
							|  |  |  | 				hotStatusHandlers.push(l); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 			removeStatusHandler: function(l) { | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				var idx = hotStatusHandlers.indexOf(l); | 
					
						
							|  |  |  | 				if(idx >= 0) hotStatusHandlers.splice(idx, 1); | 
					
						
							| 
									
										
										
										
											2014-08-13 16:46:01 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//inherit from previous dispose call
 | 
					
						
							|  |  |  | 			data: hotCurrentModuleData[moduleId] | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		return hot; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var hotStatusHandlers = []; | 
					
						
							|  |  |  | 	var hotStatus = "idle"; | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	function hotSetStatus(newStatus) { | 
					
						
							|  |  |  | 		hotStatus = newStatus; | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 		for(var i = 0; i < hotStatusHandlers.length; i++) | 
					
						
							|  |  |  | 			hotStatusHandlers[i].call(null, newStatus); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 	// while downloading
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	var hotWaitingFiles = 0; | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 	var hotChunksLoading = 0; | 
					
						
							|  |  |  | 	var hotWaitingFilesMap = {}; | 
					
						
							| 
									
										
										
										
											2014-08-25 16:19:04 +08:00
										 |  |  | 	var hotRequestedFilesMap = {}; | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	var hotAvailibleFilesMap = {}; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	var hotCallback; | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// The update info
 | 
					
						
							|  |  |  | 	var hotUpdate, hotUpdateNewHash; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 	function hotCheck(apply, callback) { | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status"); | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 		if(typeof apply === "function") { | 
					
						
							|  |  |  | 			hotApplyOnUpdate = false; | 
					
						
							|  |  |  | 			callback = apply; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			hotApplyOnUpdate = apply; | 
					
						
							|  |  |  | 			callback = callback || function(err) { if(err) throw err }; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		hotSetStatus("check"); | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 		hotDownloadManifest(function(err, update) { | 
					
						
							|  |  |  | 			if(err) return callback(err); | 
					
						
							|  |  |  | 			if(!update) { | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				hotSetStatus("idle"); | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 				callback(null, null); | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-25 16:19:04 +08:00
										 |  |  | 			hotRequestedFilesMap = {}; | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 			hotAvailibleFilesMap = {}; | 
					
						
							|  |  |  | 			hotWaitingFilesMap = {}; | 
					
						
							|  |  |  | 			for(var i = 0; i < update.c.length; i++) | 
					
						
							|  |  |  | 				hotAvailibleFilesMap[update.c[i]] = true; | 
					
						
							|  |  |  | 			hotUpdateNewHash = update.h; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			hotSetStatus("prepare"); | 
					
						
							|  |  |  | 			hotCallback = callback; | 
					
						
							|  |  |  | 			hotUpdate = {}; | 
					
						
							|  |  |  | 			/*foreachInstalledChunks*/ { | 
					
						
							|  |  |  | 				hotEnsureUpdateChunk(chunkId); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 			if(hotChunksLoading === 0 && hotWaitingFiles === 0) { | 
					
						
							|  |  |  | 				hotUpdateDownloaded(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function hotAddUpdateChunk(chunkId, moreModules) { | 
					
						
							| 
									
										
										
										
											2014-08-25 16:19:04 +08:00
										 |  |  | 		if(!hotAvailibleFilesMap[chunkId] || !hotRequestedFilesMap[chunkId]) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		hotRequestedFilesMap[chunkId] = false; | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 		for(var moduleId in moreModules) { | 
					
						
							| 
									
										
										
										
											2014-09-15 16:35:56 +08:00
										 |  |  | 			if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { | 
					
						
							|  |  |  | 				hotUpdate[moduleId] = moreModules[moduleId]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(--hotWaitingFiles === 0 && hotChunksLoading === 0) { | 
					
						
							|  |  |  | 			hotUpdateDownloaded(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 	function hotEnsureUpdateChunk(chunkId) { | 
					
						
							|  |  |  | 		if(!hotAvailibleFilesMap[chunkId]) { | 
					
						
							|  |  |  | 			hotWaitingFilesMap[chunkId] = true; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-08-25 16:19:04 +08:00
										 |  |  | 			hotRequestedFilesMap[chunkId] = true; | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			hotWaitingFiles++; | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 			hotDownloadUpdateChunk(chunkId); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 22:09:46 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 	function hotUpdateDownloaded() { | 
					
						
							|  |  |  | 		hotSetStatus("ready"); | 
					
						
							|  |  |  | 		var callback = hotCallback; | 
					
						
							|  |  |  | 		hotCallback = null; | 
					
						
							|  |  |  | 		if(!callback) return; | 
					
						
							|  |  |  | 		if(hotApplyOnUpdate) { | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 			hotApply(hotApplyOnUpdate, callback); | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			var outdatedModules = []; | 
					
						
							|  |  |  | 			for(var id in hotUpdate) { | 
					
						
							| 
									
										
										
										
											2014-09-15 16:35:56 +08:00
										 |  |  | 				if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) { | 
					
						
							|  |  |  | 					outdatedModules.push(+id); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 			callback(null, outdatedModules); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 	function hotApply(options, callback) { | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 		if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status"); | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 		if(typeof options === "function") { | 
					
						
							|  |  |  | 			callback = options; | 
					
						
							|  |  |  | 			options = {}; | 
					
						
							|  |  |  | 		} else if(options && typeof options === "object") { | 
					
						
							|  |  |  | 			callback = callback || function(err) { if(err) throw err }; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			options = {}; | 
					
						
							|  |  |  | 			callback = callback || function(err) { if(err) throw err }; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		function getAffectedStuff(module) { | 
					
						
							|  |  |  | 			var outdatedModules = [module]; | 
					
						
							| 
									
										
										
										
											2015-01-13 06:23:08 +08:00
										 |  |  | 			var outdatedDependencies = {}; | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			var queue = outdatedModules.slice(); | 
					
						
							|  |  |  | 			while(queue.length > 0) { | 
					
						
							|  |  |  | 				var moduleId = queue.pop(); | 
					
						
							|  |  |  | 				var module = installedModules[moduleId]; | 
					
						
							|  |  |  | 				if(!module || module.hot._selfAccepted) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				if(module.hot._selfDeclined) { | 
					
						
							|  |  |  | 					return new Error("Aborted because of self decline: " + moduleId); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if(moduleId === 0) { | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				for(var i = 0; i < module.parents.length; i++) { | 
					
						
							|  |  |  | 					var parentId = module.parents[i]; | 
					
						
							|  |  |  | 					var parent = installedModules[parentId]; | 
					
						
							|  |  |  | 					if(parent.hot._declinedDependencies[moduleId]) { | 
					
						
							|  |  |  | 						return new Error("Aborted because of declined dependency: " + moduleId + " in " + parentId); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if(outdatedModules.indexOf(parentId) >= 0) continue; | 
					
						
							|  |  |  | 					if(parent.hot._acceptedDependencies[moduleId]) { | 
					
						
							|  |  |  | 						if(!outdatedDependencies[parentId]) | 
					
						
							|  |  |  | 							outdatedDependencies[parentId] = []; | 
					
						
							|  |  |  | 						addAllToSet(outdatedDependencies[parentId], [moduleId]); | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					delete outdatedDependencies[parentId]; | 
					
						
							|  |  |  | 					outdatedModules.push(parentId); | 
					
						
							|  |  |  | 					queue.push(parentId); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			return [outdatedModules, outdatedDependencies]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		function addAllToSet(a, b) { | 
					
						
							|  |  |  | 			for(var i = 0; i < b.length; i++) { | 
					
						
							|  |  |  | 				var item = b[i]; | 
					
						
							|  |  |  | 				if(a.indexOf(item) < 0) | 
					
						
							|  |  |  | 					a.push(item); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// at begin all updates modules are outdated
 | 
					
						
							|  |  |  | 		// the "outdated" status can propagate to parents if they don't accept the children
 | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 		var outdatedDependencies = {}; | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		var outdatedModules = []; | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 		var appliedUpdate = {}; | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		for(var id in hotUpdate) { | 
					
						
							| 
									
										
										
										
											2014-09-15 16:35:56 +08:00
										 |  |  | 			if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) { | 
					
						
							|  |  |  | 				var moduleId = +id; | 
					
						
							|  |  |  | 				var result = getAffectedStuff(moduleId); | 
					
						
							|  |  |  | 				if(!result) { | 
					
						
							|  |  |  | 					if(options.ignoreUnaccepted) | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					hotSetStatus("abort"); | 
					
						
							|  |  |  | 					return callback(new Error("Aborted because " + moduleId + " is not accepted")); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if(result instanceof Error) { | 
					
						
							|  |  |  | 					hotSetStatus("abort"); | 
					
						
							|  |  |  | 					return callback(result); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				appliedUpdate[moduleId] = hotUpdate[moduleId]; | 
					
						
							|  |  |  | 				addAllToSet(outdatedModules, result[0]); | 
					
						
							|  |  |  | 				for(var moduleId in result[1]) { | 
					
						
							|  |  |  | 					if(Object.prototype.hasOwnProperty.call(result[1], moduleId)) { | 
					
						
							|  |  |  | 						if(!outdatedDependencies[moduleId]) | 
					
						
							|  |  |  | 							outdatedDependencies[moduleId] = []; | 
					
						
							|  |  |  | 						addAllToSet(outdatedDependencies[moduleId], result[1][moduleId]); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-09-10 20:10:05 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-23 20:59:39 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 		// Store self accepted outdated modules to require them later by the module system
 | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		var outdatedSelfAcceptedModules = []; | 
					
						
							|  |  |  | 		for(var i = 0; i < outdatedModules.length; i++) { | 
					
						
							|  |  |  | 			var moduleId = outdatedModules[i]; | 
					
						
							|  |  |  | 			if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted) | 
					
						
							| 
									
										
										
										
											2014-08-14 16:03:51 +08:00
										 |  |  | 				outdatedSelfAcceptedModules.push({ | 
					
						
							|  |  |  | 					module: moduleId, | 
					
						
							|  |  |  | 					errorHandler: installedModules[moduleId].hot._selfAccepted | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 		// Now in "dispose" phase
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		hotSetStatus("dispose"); | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 		var queue = outdatedModules.slice(); | 
					
						
							|  |  |  | 		while(queue.length > 0) { | 
					
						
							|  |  |  | 			var moduleId = queue.pop(); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			var module = installedModules[moduleId]; | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			if(!module) continue; | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var data = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Call dispose handlers
 | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			var disposeHandlers = module.hot._disposeHandlers; | 
					
						
							|  |  |  | 			for(var j = 0; j < disposeHandlers.length; j++) { | 
					
						
							|  |  |  | 				var cb = disposeHandlers[j] | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				cb(data); | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-06-20 04:31:12 +08:00
										 |  |  | 			hotCurrentModuleData[moduleId] = data; | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 			// disable module (this disables requires from this module)
 | 
					
						
							|  |  |  | 			module.hot.active = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 			// remove module from cache
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 			delete installedModules[moduleId]; | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// remove "parents" references from all children
 | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			for(var j = 0; j < module.children.length; j++) { | 
					
						
							|  |  |  | 				var child = installedModules[module.children[j]]; | 
					
						
							|  |  |  | 				if(!child) continue; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				var idx = child.parents.indexOf(moduleId); | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 				if(idx >= 0) { | 
					
						
							|  |  |  | 					child.parents.splice(idx, 1); | 
					
						
							|  |  |  | 					if(child.parents.length === 0 && child.hot && child.hot._disposeHandlers && child.hot._disposeHandlers.length > 0) { | 
					
						
							|  |  |  | 						// Child has dispose handlers and no more references, dispose it too
 | 
					
						
							|  |  |  | 						queue.push(child.id); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// remove outdated dependency from module children
 | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		for(var moduleId in outdatedDependencies) { | 
					
						
							| 
									
										
										
										
											2014-09-10 20:10:05 +08:00
										 |  |  | 			if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) { | 
					
						
							|  |  |  | 				var module = installedModules[moduleId]; | 
					
						
							|  |  |  | 				var moduleOutdatedDependencies = outdatedDependencies[moduleId]; | 
					
						
							|  |  |  | 				for(var j = 0; j < moduleOutdatedDependencies.length; j++) { | 
					
						
							|  |  |  | 					var dependency = moduleOutdatedDependencies[j]; | 
					
						
							|  |  |  | 					var idx = module.children.indexOf(dependency); | 
					
						
							|  |  |  | 					if(idx >= 0) module.children.splice(idx, 1); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 		// Not in "apply" phase
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		hotSetStatus("apply"); | 
					
						
							| 
									
										
										
										
											2013-07-05 14:35:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		hotCurrentHash = hotUpdateNewHash; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 		// insert new code
 | 
					
						
							| 
									
										
										
										
											2014-08-29 21:52:24 +08:00
										 |  |  | 		for(var moduleId in appliedUpdate) { | 
					
						
							| 
									
										
										
										
											2014-09-10 20:10:05 +08:00
										 |  |  | 			if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) { | 
					
						
							|  |  |  | 				modules[moduleId] = appliedUpdate[moduleId]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// call accept handlers
 | 
					
						
							|  |  |  | 		var error = null; | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		for(var moduleId in outdatedDependencies) { | 
					
						
							| 
									
										
										
										
											2014-09-10 20:10:05 +08:00
										 |  |  | 			if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) { | 
					
						
							|  |  |  | 				var module = installedModules[moduleId]; | 
					
						
							|  |  |  | 				var moduleOutdatedDependencies = outdatedDependencies[moduleId]; | 
					
						
							|  |  |  | 				var callbacks = []; | 
					
						
							|  |  |  | 				for(var i = 0; i < moduleOutdatedDependencies.length; i++) { | 
					
						
							|  |  |  | 					var dependency = moduleOutdatedDependencies[i]; | 
					
						
							|  |  |  | 					var cb = module.hot._acceptedDependencies[dependency]; | 
					
						
							|  |  |  | 					if(callbacks.indexOf(cb) >= 0) continue; | 
					
						
							|  |  |  | 					callbacks.push(cb); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				for(var i = 0; i < callbacks.length; i++) { | 
					
						
							|  |  |  | 					var cb = callbacks[i]; | 
					
						
							|  |  |  | 					try { | 
					
						
							|  |  |  | 						cb(outdatedDependencies); | 
					
						
							|  |  |  | 					} catch(err) { | 
					
						
							|  |  |  | 						if(!error) | 
					
						
							|  |  |  | 							error = err; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-25 02:50:41 +08:00
										 |  |  | 		// Load self accepted modules
 | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		for(var i = 0; i < outdatedSelfAcceptedModules.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-08-14 16:03:51 +08:00
										 |  |  | 			var item = outdatedSelfAcceptedModules[i]; | 
					
						
							|  |  |  | 			var moduleId = item.module; | 
					
						
							| 
									
										
										
										
											2014-09-18 05:23:45 +08:00
										 |  |  | 			hotCurrentParents = [moduleId]; | 
					
						
							| 
									
										
										
										
											2014-08-14 16:03:51 +08:00
										 |  |  | 			try { | 
					
						
							|  |  |  | 				$require$(moduleId); | 
					
						
							|  |  |  | 			} catch(err) { | 
					
						
							|  |  |  | 				if(typeof item.errorHandler === "function") { | 
					
						
							|  |  |  | 					try { | 
					
						
							|  |  |  | 						item.errorHandler(err); | 
					
						
							|  |  |  | 					} catch(err) { | 
					
						
							|  |  |  | 						if(!error) | 
					
						
							|  |  |  | 							error = err; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else if(!error) | 
					
						
							|  |  |  | 					error = err; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// handle errors in accept handlers and self accepted module load
 | 
					
						
							|  |  |  | 		if(error) { | 
					
						
							|  |  |  | 			hotSetStatus("fail"); | 
					
						
							|  |  |  | 			return callback(error); | 
					
						
							| 
									
										
										
										
											2013-06-24 19:43:28 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		hotSetStatus("idle"); | 
					
						
							|  |  |  | 		callback(null, outdatedModules); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-05 15:31:28 +08:00
										 |  |  | }); |