| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | const DependenciesBlock = require("./DependenciesBlock"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = class AsyncDependenciesBlock extends DependenciesBlock { | 
					
						
							|  |  |  | 	constructor(name, module, loc) { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 		this.chunkName = name; | 
					
						
							|  |  |  | 		this.chunks = null; | 
					
						
							|  |  |  | 		this.module = module; | 
					
						
							|  |  |  | 		this.loc = loc; | 
					
						
							| 
									
										
										
										
											2017-01-09 22:09:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	get chunk() { | 
					
						
							|  |  |  | 		throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	set chunk(chunk) { | 
					
						
							|  |  |  | 		throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 	updateHash(hash) { | 
					
						
							|  |  |  | 		hash.update(this.chunkName || ""); | 
					
						
							|  |  |  | 		hash.update(this.chunks && this.chunks.map((chunk) => { | 
					
						
							|  |  |  | 			return typeof chunk.id === "number" ? chunk.id : ""; | 
					
						
							| 
									
										
										
										
											2017-01-10 05:21:40 +08:00
										 |  |  | 		}).join(",") || ""); | 
					
						
							| 
									
										
										
										
											2017-01-09 04:07:41 +08:00
										 |  |  | 		super.updateHash(hash); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	disconnect() { | 
					
						
							|  |  |  | 		this.chunks = null; | 
					
						
							|  |  |  | 		super.disconnect(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	unseal() { | 
					
						
							|  |  |  | 		this.chunks = null; | 
					
						
							|  |  |  | 		super.unseal(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sortItems() { | 
					
						
							|  |  |  | 		super.sortItems(); | 
					
						
							|  |  |  | 		if(this.chunks) { | 
					
						
							|  |  |  | 			this.chunks.sort((a, b) => { | 
					
						
							|  |  |  | 				let i = 0; | 
					
						
							|  |  |  | 				while(true) { // eslint-disable-line no-constant-condition
 | 
					
						
							|  |  |  | 					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++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-26 08:02:33 +08:00
										 |  |  | }; |