Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created March 9, 2021 00:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guiseek/c9ec6098e469c9e6d738f9810a8d6970 to your computer and use it in GitHub Desktop.
Save guiseek/c9ec6098e469c9e6d738f9810a8d6970 to your computer and use it in GitHub Desktop.
Decorators / Tweet 3 / 08/03/2021
/**
* 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
}
}
@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