| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var DependenciesBlock = require("./DependenciesBlock"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | function AsyncDependenciesBlock(name, module, loc) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	DependenciesBlock.call(this); | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 	this.chunkName = name; | 
					
						
							| 
									
										
										
										
											2015-01-02 04:58:27 +08:00
										 |  |  | 	this.chunks = null; | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 	this.module = module; | 
					
						
							|  |  |  | 	this.loc = loc; | 
					
						
							| 
									
										
										
										
											2015-01-02 04:58:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Object.defineProperty(this, "chunk", { | 
					
						
							|  |  |  | 		get: function() { | 
					
						
							|  |  |  | 			throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		set: function() { | 
					
						
							|  |  |  | 			throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = AsyncDependenciesBlock; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AsyncDependenciesBlock.prototype = Object.create(DependenciesBlock.prototype); | 
					
						
							| 
									
										
										
										
											2016-05-20 13:39:36 +08:00
										 |  |  | AsyncDependenciesBlock.prototype.constructor = AsyncDependenciesBlock; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | AsyncDependenciesBlock.prototype.updateHash = function updateHash(hash) { | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 	hash.update(this.chunkName || ""); | 
					
						
							| 
									
										
										
										
											2015-04-21 14:35:34 +08:00
										 |  |  | 	hash.update(this.chunks && this.chunks.map(function(chunk) { | 
					
						
							|  |  |  | 		return typeof chunk.id === "number" ? chunk.id : ""; | 
					
						
							|  |  |  | 	}).join(",") || ""); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	DependenciesBlock.prototype.updateHash.call(this, hash); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AsyncDependenciesBlock.prototype.disconnect = function() { | 
					
						
							| 
									
										
										
										
											2015-01-07 16:20:48 +08:00
										 |  |  | 	this.chunks = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	DependenciesBlock.prototype.disconnect.call(this); | 
					
						
							| 
									
										
										
										
											2015-01-07 16:20:48 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | AsyncDependenciesBlock.prototype.unseal = function() { | 
					
						
							|  |  |  | 	this.chunks = null; | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.unseal.call(this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AsyncDependenciesBlock.prototype.sortItems = function() { | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.sortItems.call(this); | 
					
						
							|  |  |  | 	if(this.chunks) { | 
					
						
							|  |  |  | 		this.chunks.sort(function(a, b) { | 
					
						
							|  |  |  | 			var i = 0; | 
					
						
							|  |  |  | 			while(true) { | 
					
						
							|  |  |  | 				if(!a.modules[i] && !b.modules[i]) return 0; | 
					
						
							|  |  |  | 				if(!a.modules[i]) return -1; | 
					
						
							|  |  |  | 				if(!b.modules[i]) return 1; | 
					
						
							|  |  |  | 				if(a.modules[i].id > b.modules[i].id) return 1; | 
					
						
							|  |  |  | 				if(a.modules[i].id < b.modules[i].id) return -1; | 
					
						
							|  |  |  | 				i++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; |