forked from MapComplete/MapComplete
		
	Further development of split-road feature; refactoring of change-handling
This commit is contained in:
		
							parent
							
								
									dc4cdda3b5
								
							
						
					
					
						commit
						96ecded0b9
					
				
					 37 changed files with 967 additions and 568 deletions
				
			
		|  | @ -2,21 +2,27 @@ import {Utils} from "../Utils"; | |||
| 
 | ||||
| export class UIEventSource<T> { | ||||
| 
 | ||||
|     private static allSources: UIEventSource<any>[] = UIEventSource.PrepPerf(); | ||||
|     public data: T; | ||||
|     public trace: boolean; | ||||
|     private readonly tag: string; | ||||
|     private _callbacks = []; | ||||
|      | ||||
|     private static allSources : UIEventSource<any>[] = UIEventSource.PrepPerf(); | ||||
|      | ||||
|     static PrepPerf() : UIEventSource<any>[]{ | ||||
|         if(Utils.runningFromConsole){ | ||||
| 
 | ||||
|     constructor(data: T, tag: string = "") { | ||||
|         this.tag = tag; | ||||
|         this.data = data; | ||||
|         UIEventSource.allSources.push(this); | ||||
|     } | ||||
| 
 | ||||
|     static PrepPerf(): UIEventSource<any>[] { | ||||
|         if (Utils.runningFromConsole) { | ||||
|             return []; | ||||
|         } | ||||
|         // @ts-ignore
 | ||||
|         window.mapcomplete_performance = () => { | ||||
|             console.log(UIEventSource.allSources.length, "uieventsources created"); | ||||
|             const copy = [...UIEventSource.allSources]; | ||||
|             copy.sort((a,b) => b._callbacks.length - a._callbacks.length); | ||||
|             copy.sort((a, b) => b._callbacks.length - a._callbacks.length); | ||||
|             console.log("Topten is:") | ||||
|             for (let i = 0; i < 10; i++) { | ||||
|                 console.log(copy[i].tag, copy[i]); | ||||
|  | @ -25,13 +31,7 @@ export class UIEventSource<T> { | |||
|         } | ||||
|         return []; | ||||
|     } | ||||
| 
 | ||||
|     constructor(data: T, tag: string = "") { | ||||
|         this.tag = tag; | ||||
|         this.data = data; | ||||
|         UIEventSource.allSources.push(this); | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     public static flatten<X>(source: UIEventSource<UIEventSource<X>>, possibleSources: UIEventSource<any>[]): UIEventSource<X> { | ||||
|         const sink = new UIEventSource<X>(source.data?.data); | ||||
| 
 | ||||
|  | @ -68,6 +68,9 @@ export class UIEventSource<T> { | |||
|             // This ^^^ actually works!
 | ||||
|             throw "Don't add console.log directly as a callback - you'll won't be able to find it afterwards. Wrap it in a lambda instead." | ||||
|         } | ||||
|         if (this.trace) { | ||||
|             console.trace("Added a callback") | ||||
|         } | ||||
|         this._callbacks.push(callback); | ||||
|         return this; | ||||
|     } | ||||
|  | @ -101,12 +104,12 @@ export class UIEventSource<T> { | |||
|      */ | ||||
|     public map<J>(f: ((t: T) => J), | ||||
|                   extraSources: UIEventSource<any>[] = [], | ||||
|                   g: ((j:J, t:T) => T) = undefined): UIEventSource<J> { | ||||
|                   g: ((j: J, t: T) => T) = undefined): UIEventSource<J> { | ||||
|         const self = this; | ||||
| 
 | ||||
|         const newSource = new UIEventSource<J>( | ||||
|             f(this.data), | ||||
|             "map("+this.tag+")" | ||||
|             "map(" + this.tag + ")" | ||||
|         ); | ||||
| 
 | ||||
|         const update = function () { | ||||
|  | @ -159,9 +162,9 @@ export class UIEventSource<T> { | |||
|         return newSource; | ||||
|     } | ||||
| 
 | ||||
|     addCallbackAndRunD(callback: (data :T ) => void) { | ||||
|     addCallbackAndRunD(callback: (data: T) => void) { | ||||
|         this.addCallbackAndRun(data => { | ||||
|             if(data !== undefined && data !== null){ | ||||
|             if (data !== undefined && data !== null) { | ||||
|                 callback(data) | ||||
|             } | ||||
|         }) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue