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
function *fibonacci(n) { | |
const infinite = !n && n !== 0; | |
let current = 0; | |
let next = 1; | |
while (infinite || n--) { | |
yield current; | |
[current, next] = [next, current + next]; | |
} | |
} |
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
// session.store.ts | |
import { ID, Store, StoreConfig } from '@datorama/akita'; | |
export interface User { | |
firstName: string; | |
lastName: string; | |
token: string; | |
} | |
export interface SessionState { |
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
// session.query.ts | |
import { Query, toBoolean } from '@datorama/akita'; | |
import { filter, map } from 'rxjs/operators'; | |
import { SessionStore, SessionState } from './session.store'; | |
export class SessionQuery extends Query<SessionState> { | |
isLoggedIn$ = this.select(({ user }) => toBoolean(user)); | |
loggedInUser$ = this.select().pipe( |
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
// student.model.ts | |
import { ID, guid } from '@datorama/akita'; | |
export interface Student { | |
id: ID; | |
name: string; | |
sex: 'Male' | 'Female'; | |
standard: number; | |
quarterlyScore: number; | |
halfyearlyScore: number; |
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
// student.store.ts | |
import { EntityState, EntityStore, StoreConfig } from '@datorama/akita'; | |
import { Student } from './student.model'; | |
export interface StudentState extends EntityState<Student> { } | |
@StoreConfig({ | |
name: 'students' | |
}) | |
export class StudentStore extends EntityStore<StudentState, Student> { |
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
// student.query.ts | |
import { QueryEntity } from '@datorama/akita'; | |
export class StudentQuery extends QueryEntity<StudentState, Student> { | |
studentsGraphData$ = this.selectAll().pipe( | |
map(this.getStudentGraphData.bind(this)) | |
); | |
constructor(protected store: StudentStore) { |
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
// student-data.service.ts | |
import { timer, Observable } from 'rxjs'; | |
import { mapTo } from 'rxjs/operators'; | |
import { Student } from './student.model'; | |
import { guid } from '@datorama/akita'; | |
const students: Array<Student> = [ | |
{ | |
id: guid(), | |
name: 'Mohan Ram', |
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
// student.service.ts | |
import { noop, ID } from '@datorama/akita'; | |
// importing respective dependencies here | |
// ... | |
export class StudentService { | |
constructor( | |
private studentDataService: StudentDataService, | |
private studentStore: StudentStore, |
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
// app.module.ts | |
import { AkitaNgDevtools } from '@datorama/akita-ngdevtools'; | |
import { environment } from '../environments/environment'; | |
@NgModule({ | |
imports: [ | |
environment.production ? [] : AkitaNgDevtools.forRoot() | |
], | |
declarations: [AppComponent], | |
bootstrap: [AppComponent] |
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
/** | |
* Below codes are from the type declaration of Akita | |
*/ | |
// An interface to represent objects | |
export interface HashMap<T> { | |
[id: string]: T; | |
} | |
/** |