Skip to content

Instantly share code, notes, and snippets.

View YonathanMeguira's full-sized avatar
🤩
Happy

Yonathan Meguira YonathanMeguira

🤩
Happy
View GitHub Profile
@YonathanMeguira
YonathanMeguira / EntityState.ts
Last active August 19, 2018 06:42
Entity.ts
export interface EntityState<E> {
entities: HashMap<E>;
ids: ID[];
loading: boolean;
error: any;
}
@YonathanMeguira
YonathanMeguira / model.ts
Last active August 19, 2018 06:35
model.ts
import { ID } from '@datorama/akita';
export interface List {
id: ID;
name: string;
date: number | Date;
items: Item[];
}
export interface Item {
@YonathanMeguira
YonathanMeguira / add.ts
Last active August 21, 2018 08:25
add component
import { List, Item, ShopikaService } from '../state';
export class AddListComponent {
list: List;
constructor(private shopikaService: ShopikaService) { }
saveList() {
this.shopikaService.addList(this.list);
}
import './polyfills';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { enableAkitaProdMode, persistState } from '@datorama/akita';
enableAkitaProdMode();
@YonathanMeguira
YonathanMeguira / store.ts
Last active August 19, 2018 06:44
store.ts
import { EntityState, EntityStore, StoreConfig, getInitialActiveState, ActiveState } from '@datorama/akita';
import { List } from './shopika.model';
export interface ListsState extends EntityState<List>, ActiveState { }
@StoreConfig({ name: 'lists' })
export class ListStore extends EntityStore<ListsState, List> {
constructor() {
super();
}
@YonathanMeguira
YonathanMeguira / query.ts
Last active August 21, 2018 08:22
query.ts
import { QueryEntity } from '@datorama/akita';
import { ListStore, ListsState } from './shopika.store';
import { List, Item } from './shopika.model';
export class ListQuery extends QueryEntity<ListsState, List> {
constructor(protected store: ListStore) {
super(store);
}
}
@YonathanMeguira
YonathanMeguira / list.component.ts
Last active September 5, 2018 09:28
shopping list
import { ListQuery, List } from '../state';
import { ShopikaService } from '../state/shopika.service';
import { ID } from '@datorama/akita';
import { Observable } from 'rxjs';
export class ListsComponent implements OnInit {
lists$: Observable<List[]>;
constructor(
private listQuery: ListQuery,
@YonathanMeguira
YonathanMeguira / edit.component.ts
Last active August 21, 2018 08:24
shopika-edit.component
import { List, Item, ShopikaService, ListQuery } from '../state';
import { ID } from '@datorama/akita';
export class EditComponent implements OnInit {
list: List;
constructor(
private shopikaService: ShopikaService,
private listQuery: ListQuery
) { }
@YonathanMeguira
YonathanMeguira / add.component.ts
Created July 26, 2018 14:07
shopika.add.component.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/index';
import { List, Item } from './shopika.model';
import { ID } from '@datorama/akita';
import { of } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ShopikaDataService {
@YonathanMeguira
YonathanMeguira / item.component.ts
Last active July 26, 2018 14:15
item.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { ItemQuery, ListQuery, List, Item, ShopikaService } from '../state';
import { ID } from '@datorama/akita';
@Component({
selector: 'app-edit',
templateUrl: './edit.component.html',
styleUrls: ['./edit.component.css']
})