This file contains hidden or 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 EntityState<E> { | |
entities: HashMap<E>; | |
ids: ID[]; | |
loading: boolean; | |
error: any; | |
} |
This file contains hidden or 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
import { ID } from '@datorama/akita'; | |
export interface List { | |
id: ID; | |
name: string; | |
date: number | Date; | |
items: Item[]; | |
} | |
export interface Item { |
This file contains hidden or 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
import { List, Item, ShopikaService } from '../state'; | |
export class AddListComponent { | |
list: List; | |
constructor(private shopikaService: ShopikaService) { } | |
saveList() { | |
this.shopikaService.addList(this.list); | |
} |
This file contains hidden or 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
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(); |
This file contains hidden or 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
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(); | |
} |
This file contains hidden or 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
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); | |
} | |
} |
This file contains hidden or 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
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, |
This file contains hidden or 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
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 | |
) { } |
This file contains hidden or 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
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 { |
This file contains hidden or 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
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'] | |
}) |