import { Injectable } from '@angular/core' ; import { Storage } from '../../../services/storage' ; /**
 * Most recently used hashtags service. Based off default storage service.
 */ @ Injectable ( ) export class MruService { constructor ( protected storage ) { } param key reset ( key ) { this . storage . set ( this . buildKey ( key ) , JSON . stringify ( [ ] ) ) ; return this ; } param key param tags push ( key , tags ) { const items = [ ... tags , ... this . fetch ( key ) ] . filter ( Boolean ) . filter ( ( value , index , self ) => self . indexOf ( value ) === index ) . slice ( 0 , 500 ) ; this . storage . set ( this . buildKey ( key ) , JSON . stringify ( items ) ) ; return this ; } param key fetch ( key ) { return JSON . parse ( this . storage . get ( this . buildKey ( key ) ) || '[]' ) || [ ] ; } param key protected buildKey ( key ) { return `mru:hashtags:${ key || '_' }` ; } }