Created
March 9, 2021 00:27
-
-
Save guiseek/c9ec6098e469c9e6d738f9810a8d6970 to your computer and use it in GitHub Desktop.
Decorators / Tweet 3 / 08/03/2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Confirm Action | |
* | |
* Keep it Simple Sir | |
* | |
* @param message | |
*/ | |
export function Confirm(message: string) { | |
/** | |
* @param target é a classe, no nosso claso o componente ListaComponent | |
* @param key é o método qual o decorator está interceptando | |
* @param descriptor pode ser usado para observar, modificar ou substituir as definições de um acessador | |
*/ | |
return function ( | |
target: Object, | |
key: string | symbol, | |
descriptor: PropertyDescriptor | |
) { | |
const original = descriptor.value | |
descriptor.value = function (...args: any[]) { | |
const result = window.confirm(message) | |
if (result) { | |
return original.apply(this, args) | |
} | |
return null | |
} | |
return descriptor | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Confirm('Remover usuário?') | |
onRemove(user: User) { | |
this._server.deleteUser(user.id) | |
.pipe(takeUntil(this._destroy)) | |
.subscribe( | |
() => this._server.loadUsers(), | |
(err) => this._error.next(err) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment