This file contains 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
@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 | |
} |
This file contains 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
@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); |
This file contains 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
@Injectable() | |
export class SettingsFacade { | |
constructor( | |
private cashflowCategoryApi: CashflowCategoryApi, | |
private settingsState: SettingsState | |
) { } | |
get isUpdating$(): Observable<boolean> { | |
return this.settingsState.isUpdating$; |
This file contains 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
@Injectable() | |
export class CashflowCategoryApi { | |
readonly API = '/api/cashflowCategories'; | |
constructor(private http: HttpClient) {} | |
getCashflowCategories(): Observable<CashflowCategory[]> { | |
return this.http.get<CashflowCategory[]>(this.API); | |
} |
This file contains 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
<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> |
This file contains 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
@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>; |
This file contains 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
@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>(); |
This file contains 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
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 |
This file contains 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
export interface DateFormatter { | |
getTimeFromNow(dateTime: string): string | |
} |
This file contains 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
export class MomentAdapter implements DateFormatter { | |
getTimeFromNow(dateTime: string): string { | |
return moment(dateTime, 'DD/MM/YYYY, HH:mm:ss').locale('pt-BR').fromNow() | |
} | |
} |
OlderNewer