fix(platform-browser): support 0/false/null values in transfer_state (#22179)
Issue #22178 PR Close #22179
This commit is contained in:
parent
16d1700a8e
commit
6435ecd3c6
|
@ -93,7 +93,9 @@ export class TransferState {
|
|||
/**
|
||||
* Get the value corresponding to a key. Return `defaultValue` if key is not found.
|
||||
*/
|
||||
get<T>(key: StateKey<T>, defaultValue: T): T { return this.store[key] as T || defaultValue; }
|
||||
get<T>(key: StateKey<T>, defaultValue: T): T {
|
||||
return this.store[key] !== undefined ? this.store[key] as T : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value corresponding to a key.
|
||||
|
|
|
@ -70,6 +70,27 @@ import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
|
|||
expect(transferState.hasKey(TEST_KEY)).toBe(true);
|
||||
});
|
||||
|
||||
it('supports setting and accessing value \'0\' via get', () => {
|
||||
const transferState: TransferState = TestBed.get(TransferState);
|
||||
transferState.set(TEST_KEY, 0);
|
||||
expect(transferState.get(TEST_KEY, 20)).toBe(0);
|
||||
expect(transferState.hasKey(TEST_KEY)).toBe(true);
|
||||
});
|
||||
|
||||
it('supports setting and accessing value \'false\' via get', () => {
|
||||
const transferState: TransferState = TestBed.get(TransferState);
|
||||
transferState.set(TEST_KEY, false);
|
||||
expect(transferState.get(TEST_KEY, 20)).toBe(false);
|
||||
expect(transferState.hasKey(TEST_KEY)).toBe(true);
|
||||
});
|
||||
|
||||
it('supports setting and accessing value \'null\' via get', () => {
|
||||
const transferState: TransferState = TestBed.get(TransferState);
|
||||
transferState.set(TEST_KEY, null);
|
||||
expect(transferState.get(TEST_KEY, 20)).toBe(null);
|
||||
expect(transferState.hasKey(TEST_KEY)).toBe(true);
|
||||
});
|
||||
|
||||
it('supports removing keys', () => {
|
||||
const transferState: TransferState = TestBed.get(TransferState);
|
||||
transferState.set(TEST_KEY, 20);
|
||||
|
|
Loading…
Reference in New Issue