import { inject , injectable } from 'inversify' ; import * as apid from '../../../../api' ; import IChannelsApiModel from '../api/channels/IChannelsApiModel' ; import IChannelModel , { Channel } from './IChannelModel' ; @ injectable ( ) export default class ChannelModel implements IChannelModel { private channelsApiModel : IChannelsApiModel ; private channels : apid . ChannelItem [ ] = [ ] ; private channelsIndex : { [ channelId ] : apid . ChannelItem ; } = { } ; constructor ( @ inject ( 'IChannelsApiModel' ) channelsApiModel ) { this . channelsApiModel = channelsApiModel ; } return public async fetchChannels ( ) { this . channels = await this . channelsApiModel . getChannels ( ) ; this . channelsIndex = { } ; for ( const c of this . channels ) { this . channelsIndex [ c . id ] = c ; } } param isHalfWidth public getChannels ( isHalfWidth ) { return this . channels . map ( c => { return this . toChannel ( c , isHalfWidth ) ; } ) ; } param item param isHalfWidth return private toChannel ( item , isHalfWidth ) { return { id : item . id , serviceId : item . serviceId , networkId : item . networkId , name : isHalfWidth === true ? item . halfWidthName : item . name , remoteControlKeyId : item . remoteControlKeyId , hasLogoData : item . hasLogoData , channelType : item . channelType , channel : item . channelType , } ; } param id param isHalfWidth return public findChannel ( id , isHalfWidth ) { const item = this . channelsIndex [ id ] ; return typeof item === 'undefined' ? null : this . toChannel ( item , isHalfWidth ) ; } }