Skip to content

Instantly share code, notes, and snippets.

View webmasterdevlin's full-sized avatar

Devlin Duldulao webmasterdevlin

View GitHub Profile
@webmasterdevlin
webmasterdevlin / heroes.store
Created July 28, 2019 13:08
Akita Store: src/app/heroes/heroes.store.ts
import { EntityStore, StoreConfig } from '@datorama/akita';
import { HeroesState, HeroModel } from './hero.model';
import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'heroes' })
export class HeroesStore extends EntityStore<HeroesState, HeroModel> {
constructor() {
super();
}
@webmasterdevlin
webmasterdevlin / hero.model.ts
Created July 28, 2019 12:56
Akita Model: src/app/heroes/hero.model.ts
import { ID, EntityState } from '@datorama/akita';
export type HeroModel = {
id: ID;
firstName: string;
lastName: string;
house: string;
knownAs: string;
};
@webmasterdevlin
webmasterdevlin / heroes.component.html
Created July 3, 2019 22:01
Angular HTML Template : app/heroes/container/heroes.component.html
<div class="container">
<app-new-item-form
[isShowNewItemForm]="isShowNewItemForm"
[newItemForm]="newItemForm"
(handleSubmit)="onSubmit()"
(handleCancelForm)="cancelForm()"
(handleShowNewItemForm)="showNewItemForm()"
></app-new-item-form>
<app-item-list
[editItemUrl]="editItemUrl"
@webmasterdevlin
webmasterdevlin / app.module.ts
Last active July 3, 2019 21:50
NgXS Module: src/app/app.module.ts
import { NgModule } from "@angular/core";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { NgxsModule } from "@ngxs/store";
import { HeroState } from "./heroes/hero.state";
import { NgxsReduxDevtoolsPluginModule } from "@ngxs/devtools-plugin";
import { NgxsLoggerPluginModule } from "@ngxs/logger-plugin";
@webmasterdevlin
webmasterdevlin / heroes.componet.ts
Created July 3, 2019 21:12
NgXS Store: src/app/heroes/container/heroes.component.ts
import { Component, OnInit } from "@angular/core";
import { Select, Store } from "@ngxs/store";
import { AddHero, DeleteHero, GetHeroes } from "../hero.action";
import { HeroState } from "../hero.state";
import { Observable } from "rxjs";
import { Hero } from "../hero.model";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
@Component({
selector: "app-heroes",
@webmasterdevlin
webmasterdevlin / hero.state.ts
Created July 3, 2019 20:48
NgXS State: src/app/heroes/hero.state.ts
import { Hero } from "./hero.model";
import { Action, Selector, State, StateContext } from "@ngxs/store";
import { HeroService } from "./hero.service";
import {
AddHero,
DeleteHero,
GetHeroById,
GetHeroes,
UpdateHero
} from "./hero.action";
@webmasterdevlin
webmasterdevlin / hero.actions.ts
Created July 3, 2019 20:26
NgXS Actions: src/app/heroes/hero.action.ts
import { Hero } from "./hero.model";
export class GetHeroes {
static readonly type = "[Hero] Get";
}
export class GetHeroById {
static readonly type = "[Hero] GetById";
constructor(public id: string) {}
}
@webmasterdevlin
webmasterdevlin / heroes.component.html
Last active March 15, 2019 01:10
Angular HTML Template : src/app/heroes/container/heroes.component.html
<div class="container">
<app-new-item-form
[isShowNewItemForm]="isShowNewItemForm"
[newItemForm]="newItemForm"
(handleSubmit)="onSubmit()"
(handleCancelForm)="cancelForm()"
(handleShowNewItemForm)="showNewItemForm()"
></app-new-item-form>
<app-item-list
@webmasterdevlin
webmasterdevlin / heroes.component.ts
Last active March 15, 2019 01:10
Angular Smart Component : src/app/heroes/container/heroes.component.ts
import { Component, OnInit } from "@angular/core";
import { Store } from "@ngrx/store";
import { selectHero, State } from "../../reducers";
import { Hero } from "../../models/hero.model";
import * as heroActions from "../../actions/hero.actions";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
@Component({
selector: "app-heroes",
@webmasterdevlin
webmasterdevlin / app.module.ts
Last active March 14, 2019 16:31
NgRx Module : src/app/app.module.ts
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { StoreModule } from "@ngrx/store";
import { reducers, metaReducers } from "./reducers";
import { StoreDevtoolsModule } from "@ngrx/store-devtools";
import { environment } from "../environments/environment";
import { AppRoutingModule } from "./app-routing.module";
import { HeaderNavComponent } from "./shared/components/header-nav.component";
import { EffectsModule } from "@ngrx/effects";
import { HttpClientModule } from "@angular/common/http";