Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3556 from jrsquared/execution-group
refactor(core/cache): Convert collapsibleSectionStateCache to TS
- Loading branch information
Showing
6 changed files
with
54 additions
and
39 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
'use strict'; | ||
|
||
import { COLLAPSIBLE_SECTION_STATE_CACHE } from './collapsibleSectionStateCache'; | ||
let angular = require('angular'); | ||
|
||
module.exports = angular | ||
.module('spinnaker.core.cache', [ | ||
require('./collapsibleSectionStateCache.js'), | ||
COLLAPSIBLE_SECTION_STATE_CACHE, | ||
]); |
35 changes: 0 additions & 35 deletions
35
app/scripts/modules/core/cache/collapsibleSectionStateCache.js
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
app/scripts/modules/core/cache/collapsibleSectionStateCache.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ICache, ICacheFactory } from './deckCache.service'; | ||
import { module } from 'angular'; | ||
|
||
|
||
export class CollapsibleSectionStateCache { | ||
private stateCache: ICache; | ||
|
||
static get $inject(): string[] { return ['CacheFactory']; } | ||
constructor(private CacheFactory: ICacheFactory) { | ||
const cacheId = 'collapsibleSectionStateCache'; | ||
|
||
try { | ||
this.CacheFactory.createCache(cacheId, { | ||
maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days | ||
deleteOnExpire: 'aggressive', | ||
storageMode: 'localStorage', | ||
}); | ||
} catch (e) { | ||
// trying to create a cache multiple times throws and Error | ||
} | ||
|
||
this.stateCache = CacheFactory.get(cacheId); | ||
} | ||
|
||
public isSet(heading: string): boolean { | ||
return this.stateCache.get(heading) !== undefined; | ||
} | ||
|
||
public isExpanded(heading: string): boolean { | ||
return this.stateCache.get(heading) === true; | ||
} | ||
|
||
public setExpanded(heading: string, expanded: boolean) { | ||
this.stateCache.put(heading, !!expanded); | ||
} | ||
} | ||
|
||
export let collapsibleSectionStateCache: CollapsibleSectionStateCache = undefined; | ||
export const COLLAPSIBLE_SECTION_STATE_CACHE = 'spinnaker.core.cache.collapsibleSectionState'; | ||
module(COLLAPSIBLE_SECTION_STATE_CACHE, [ | ||
require('angular-cache') | ||
]) | ||
.service('collapsibleSectionStateCache', CollapsibleSectionStateCache) | ||
.run(($injector: any) => collapsibleSectionStateCache = <CollapsibleSectionStateCache>$injector.get('collapsibleSectionStateCache')); |
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
4 changes: 3 additions & 1 deletion
4
app/scripts/modules/core/presentation/collapsibleSection/collapsibleSection.directive.js
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
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