Refactor forget function to use async/await
This commit is contained in:
		
							parent
							
								
									921dae135b
								
							
						
					
					
						commit
						6a5efb219d
					
				
					 1 changed files with 38 additions and 42 deletions
				
			
		|  | @ -305,28 +305,25 @@ export async function write(PATH, DATA, CLOUD = -1) { | |||
| @param {int} CLOUD the storage of the data | ||||
| @return {boolean} the user's confirmation | ||||
| */ | ||||
| export function forget(preference, subpreference, CLOUD = 0) { | ||||
| 	let forget_action = false; | ||||
| 
 | ||||
| 	(async () => { | ||||
| export async function forget(preference, subpreference, CLOUD = 0) { | ||||
| 	// Import alerts module.
 | ||||
| 		let alerts = (await import(chrome.runtime.getURL(`gui/scripts/alerts.js`)))[ | ||||
| 			`alerts` | ||||
| 		]; | ||||
| 	let alerts = (await import(chrome.runtime.getURL(`gui/scripts/alerts.js`))).default; | ||||
| 
 | ||||
| 	// Confirm the action.
 | ||||
| 		let forget_action = alerts.confirm_action(); | ||||
| 	let forget_action = await alerts.confirm(); | ||||
| 
 | ||||
| 	if (forget_action) { | ||||
| 		if (preference) { | ||||
| 			if (subpreference) { | ||||
| 				 | ||||
| 				// Get the data.
 | ||||
| 					data = read(preference, CLOUD); | ||||
| 				let DATA = await read(preference, CLOUD); | ||||
| 
 | ||||
| 				// Should only run when existent
 | ||||
| 					if (data[subpreference]) { | ||||
| 						delete data[subpreference]; | ||||
| 						write([preference, subpreference], data, CLOUD); | ||||
| 				if (DATA[subpreference]) { | ||||
| 					delete DATA[subpreference]; | ||||
| 					console.log(preference, DATA, CLOUD); | ||||
| 					write(preference, DATA, CLOUD); | ||||
| 				} | ||||
| 			} else { | ||||
| 				// Remove that particular data.
 | ||||
|  | @ -355,7 +352,6 @@ export function forget(preference, subpreference, CLOUD = 0) { | |||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	})(); | ||||
| 
 | ||||
| 	return forget_action; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue