forked from angular-redux/store
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes angular-redux#413] allow tests to reset observables cached by …
…decorators (angular-redux#414) [Fixes angular-redux#413] allow tests to reset observables cached by decorators `@select` and `@select$` cache the results of their selections, in order to avoid memory leaks. However we need to be able to reset these cached copies when MockNgRedux.reset() is called. The solution is to track the cached selections in a lookup table instead of as closure variables in the decorator itself.
- Loading branch information
1 parent
92fbda3
commit 9a9f77e
Showing
12 changed files
with
80 additions
and
20 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 |
---|---|---|
|
@@ -13,3 +13,4 @@ circle.yml | |
npm-debug.log | ||
.compiled | ||
ISSUE_TEMPLATE.md | ||
*.tgz |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Selector, Comparator, Transformer } from '../components/selectors'; | ||
|
||
const toKey = (val: Object | Array<any> | Function | String) => | ||
val ? val.toString() : ''; | ||
|
||
const computeKey = ( | ||
selector: Selector<any, any>, | ||
transformer: Transformer<any, any>, | ||
comparator: Comparator) => | ||
`s:${toKey(selector)}:t:${toKey(transformer)}:c:${toKey(comparator)}`; | ||
|
||
/** | ||
* Used to pool Observables created by @select and @select$. This | ||
* avoids memory leaks and improves efficiency. | ||
* @hidden | ||
*/ | ||
export class SelectionMap { | ||
private _map: { [id: string]: Observable<any> } = {}; | ||
|
||
set( | ||
selector: Selector<any, any>, | ||
transformer: Transformer<any, any>, | ||
comparator: Comparator, | ||
selection: Observable<any>): void { | ||
const key = computeKey(selector, transformer, comparator); | ||
this._map[key] = selection; | ||
} | ||
|
||
get( | ||
selector: Selector<any, any>, | ||
transformer: Transformer<any, any>, | ||
comparator: Comparator): Observable<any> { | ||
const key = computeKey(selector, transformer, comparator); | ||
return this._map[key]; | ||
} | ||
|
||
reset() { | ||
this._map = {}; | ||
} | ||
} | ||
|
||
/** @hidden */ | ||
export const selectionMap = new SelectionMap(); |
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