Skip to content

Instantly share code, notes, and snippets.

View andrewarosario's full-sized avatar

Andrew Rosário andrewarosario

View GitHub Profile
@Component({
selector: 'categories',
templateUrl: './categories.component.html',
styleUrls: ['./categories.component.scss']
})
export class CategoriesComponent implements OnInit {
@Input() cashflowCategories$: CashflowCategory[];
newCategory: CashflowCategory = new CashflowCategory();
isUpdating$: Observable<boolean>;
@Injectable()
export class SettingsFacade {
constructor(
private cashflowCategoryApi: CashflowCategoryApi,
private settingsState: SettingsState
) { }
get isUpdating$(): Observable<boolean> {
return this.settingsState.isUpdating$;
@Injectable()
export class RecordsFacade {
private records$: Observable<Record[]>;
constructor(private recordApi: RecordApi) {
this.records$ = this.recordApi
.getRecords()
.pipe(shareReplay(1)); // armazena os dados em cache
}
@Injectable()
export class SettingsState {
// definimos os estados iniciais nos BehaviorSubject
// ninguém fora da SettingsState tem acesso a eles
// A alteração no estado deve ser tratada por métodos especializados da classe
// (por exemplo: addCashflowCategory, updateCashflowCategory, etc)
// criamos um BehaviorSubject para cada entidade do estado
// mais abaixo criaremos getters e setters para que os mesmos sejam acessados pelos Facades
private _updating$ = new BehaviorSubject<boolean>(false);
@Injectable()
export class CashflowCategoryApi {
readonly API = '/api/cashflowCategories';
constructor(private http: HttpClient) {}
getCashflowCategories(): Observable<CashflowCategory[]> {
return this.http.get<CashflowCategory[]>(this.API);
}
<div class="categories">
<p>Cashflow Categories</p>
<app-category
*ngFor="let category of settingsFacade.cashflowCategories$ | async"
[category]="category"
(update)="settingsFacade.updateCashflowCategory($event)"
(remove)="settingsFacade.removeCashflowCategory($event)"
></app-category>
@Component({
selector: 'app-category',
templateUrl: './category.component.html',
styleUrls: ['./category.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CategoryComponent {
@Input() category: CashflowCategory;
@Output() change = new EventEmitter<CashflowCategory>();
const venom = require('venom-bot');
venom
.create()
.then((client) => start(client));
function start(client) {
client.onMessage((message) => {
if (message.body === 'Oi' || message.body === 'Olá') {
client
export interface DateFormatter {
getTimeFromNow(dateTime: string): string
}
export class MomentAdapter implements DateFormatter {
getTimeFromNow(dateTime: string): string {
return moment(dateTime, 'DD/MM/YYYY, HH:mm:ss').locale('pt-BR').fromNow()
}
}