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
class HashMapDemo { | |
public static void main(String[ ] args) { | |
String key = "superman"; | |
int size = 15; | |
System.out.println("Key: " + key); | |
int hashCode = key.hashCode(); | |
System.out.println("HashCode: " + hashCode); | |
System.out.println("HashCode (Binary): " + Integer.toBinaryString(hashCode)); | |
int h; | |
int hash = (h = key.hashCode()) ^ (h >>> 16); |
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
describe('getBooks action', function () { | |
it("should call getBooks and redirect to booksLoaded action", (done) => { | |
spyOn(booksService, "getBooks").and.returnValue(of(books)) | |
actions$ = of(BookStoreActions.loadBooks); | |
effects.loadBooks$.subscribe(res => { | |
expect(booksService.getBooks).toHaveBeenCalled() | |
expect(res).toEqual(BookStoreActions.booksLoaded({books: books})) | |
done() | |
}) | |
}) |
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
loadBooks$ = createEffect(() => this.actions$.pipe( | |
ofType(BookStoreActions.loadBooks), | |
mergeMap(() => this.booksService.getBooks().pipe( | |
map(books => BookStoreActions.booksLoaded({books})), | |
catchError(() => EMPTY) | |
)) | |
)); |
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
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
providers: [ | |
BooksEffects, | |
provideMockActions(() => actions$), | |
provideMockStore({initialState}), | |
], | |
imports: [HttpClientModule] | |
}) | |
booksService = TestBed.inject(BooksService) |
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
let store: MockStore<AppState>; | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
declarations: [AppComponent, ItemComponent], | |
imports: [ReactiveFormsModule], | |
providers: [provideMockStore()], | |
schemas: [CUSTOM_ELEMENTS_SCHEMA] | |
}); | |
fixture = TestBed.createComponent(AppComponent); | |
app = fixture.componentInstance; |
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
ngOnInit(): void{ | |
this.loadBooks(); | |
this.store.select(Selector.books).subscribe(books => this.books$ = books); | |
this.store.select(Selector.selectedBook).subscribe(book => { | |
this.selectedBook = book; | |
}); | |
this.store.select(Selector.showDetail).subscribe(showDetail => { | |
this.showDetail = showDetail; | |
showDetail ? this.showPopup() : this.hidePopup(); | |
}); |
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
@NgModule({ | |
declarations: [ | |
AppComponent, | |
ItemComponent | |
], | |
imports: [ | |
BrowserModule, | |
HttpClientModule, | |
HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, {dataEncapsulation: false}), | |
ReactiveFormsModule, |
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
@NgModule({ | |
declarations: [ | |
AppComponent, | |
ItemComponent | |
], | |
imports: [ | |
BrowserModule, | |
HttpClientModule, | |
HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, {dataEncapsulation: false}), | |
ReactiveFormsModule, |
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 BooksEffects { | |
loadBooks$ = createEffect(() => this.actions$.pipe( | |
ofType(BookStoreActions.loadBooks), | |
mergeMap(() => this.booksService.getBooks().pipe( | |
map(books => BookStoreActions.booksLoaded({books})), | |
catchError(() => EMPTY) | |
)) | |
)); |
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
import {createReducer, on} from "@ngrx/store"; | |
import {BookStoreActions} from "./books.actions"; | |
import {BookStore} from "./books.state"; | |
export const initialState: BookStore = { books: [], selectedBook: undefined, showDetail: false}; | |
export const booksReducer = createReducer( | |
initialState, | |
on(BookStoreActions.booksLoaded, (state, {books}) => ({...state, books: books})), | |
on(BookStoreActions.showBook, (state, {book}) => ({...state, selectedBook: book, showDetail: true})), |
NewerOlder