import Immutable from "immutable" ; import SummaryArticle from "./summaryArticle" ; type Articles = Immutable . List < any > ; class SummaryPart extends Immutable . Record ( { level : String ( ) , title : String ( ) , articles : Immutable . List ( ) , } ) { getLevel ( ) { return this . get ( "level" ) ; } getTitle ( ) { return this . get ( "title" ) ; } getArticles ( ) { return this . get ( "articles" ) ; } return { string } createChildLevel ( ) { const level = this . getLevel ( ) ; const subArticles = this . getArticles ( ) ; const childLevel = `${ level }.${ subArticles . size + 1 }` ; return childLevel ; } param { Object } def return { SummaryPart } static create ( def , level ) { const articles = ( def . articles || [ ] ) . map ( ( article , i ) => { if ( article instanceof SummaryArticle ) { return article ; } return SummaryArticle . create ( article , [ level , i + 1 ] . join ( "." ) ) ; } ) ; return new SummaryPart ( { level : String ( level ) , title : def . title , articles : Immutable . List ( articles ) , } ) ; } } export default SummaryPart ;