import { ObservableVocabulary , ObservableWritingQuestion , } from '@ulangi/ulangi-observable' ; import { OrderedMap } from 'immutable' ; import * as uuid from 'uuid' ; import { VocabularyIterator } from './VocabularyIterator' ; export class WritingQuestionIterator { private numberOfQuestions : number ; private vocabularyIterator : VocabularyIterator < ObservableVocabulary > ; public constructor ( vocabularyList ? ) { this . vocabularyIterator = new VocabularyIterator ( vocabularyList ? OrderedMap ( vocabularyList ) : undefined ) ; this . numberOfQuestions = this . vocabularyIterator . getSize ( ) ; } public update ( key , value ) { this . vocabularyIterator . update ( key , value ) ; } public current ( ) { return this . makeQuestion ( this . vocabularyIterator . current ( ) ) ; } public previous ( ) { const previousVocabulary = this . vocabularyIterator . previous ( ) ; return this . makeQuestion ( previousVocabulary ) ; } public next ( ) { const nextVocabulary = this . vocabularyIterator . next ( ) ; return this . makeQuestion ( nextVocabulary ) ; } public isDone ( ) { return this . vocabularyIterator . isDone ( ) ; } public getNumberOfQuestions ( ) { return this . numberOfQuestions ; } public getNumberOfQuestionsLeft ( ) { return this . vocabularyIterator . getRemainingSize ( ) ; } private makeQuestion ( vocabulary ) { return { questionId : uuid . v4 ( ) , testingVocabulary : vocabulary , givenDefinitions : vocabulary . definitions , } ; } }