-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent timing out one tab or window if another tab have activi…
…ty (#33) * feat: prevent timing out one tab or window if another tab have activity add a LocalStorageExpiry that put the expiry value in LocalStorage. If localStorage is not supported by the browser, will store the expiry value in memory. Can change expiry key name in localstorage for multiple instance.
- Loading branch information
Showing
16 changed files
with
761 additions
and
243 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 |
---|---|---|
|
@@ -36,3 +36,6 @@ typings | |
# Build artifacts | ||
dist | ||
.tmp | ||
|
||
# VS Code config | ||
.vscode |
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import {DocumentInterruptSource} from './src/documentinterruptsource'; | ||
import {StorageInterruptSource} from './src/storageinterruptsource'; | ||
|
||
export * from './src/idle'; | ||
export * from './src/interruptargs'; | ||
export * from './src/interruptsource'; | ||
export * from './src/eventtargetinterruptsource'; | ||
export * from './src/documentinterruptsource'; | ||
export * from './src/windowinterruptsource'; | ||
export * from './src/storageinterruptsource'; | ||
export * from './src/keepalivesvc'; | ||
export * from './src/idleexpiry'; | ||
export * from './src/simpleexpiry'; | ||
export * from './src/localstorage'; | ||
export * from './src/localstorageexpiry'; | ||
|
||
export const DEFAULT_INTERRUPTSOURCES: any[] = [new DocumentInterruptSource( | ||
'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll')]; | ||
'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll'), new StorageInterruptSource()]; | ||
|
||
export {NgIdleModule} from './src/module'; |
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,42 @@ | ||
import { AlternativeStorage } from './alternativestorage'; | ||
|
||
describe('core/AlternativeStorage', () => { | ||
|
||
let storage: Storage; | ||
|
||
beforeEach(() => { | ||
storage = new AlternativeStorage(); | ||
}); | ||
|
||
it('setItem() and getItem() should works properly', () => { | ||
expect(storage.getItem('key')).toBeNull(); | ||
storage.setItem('key', 'value'); | ||
expect(storage.getItem('key')).toBe('value'); | ||
}); | ||
|
||
it('length() returns current value', () => { | ||
expect(storage.length).toBe(0); | ||
storage.setItem('key', 'value'); | ||
expect(storage.length).toBe(1); | ||
}); | ||
|
||
it('clear() must clear current storage', () => { | ||
storage.setItem('key', 'value'); | ||
expect(storage.length).toBe(1); | ||
storage.clear(); | ||
expect(storage.length).toBe(0); | ||
}); | ||
|
||
it('key() must return key name ', () => { | ||
expect(storage.key(0)).toBeNull(); | ||
storage.setItem('key', 'value'); | ||
expect(storage.key(0)).toBe('key'); | ||
}); | ||
|
||
it('remove() must remove item', () => { | ||
storage.setItem('key', 'value'); | ||
storage.removeItem('key'); | ||
expect(storage.getItem('key')).toBeNull(); | ||
}); | ||
|
||
}); |
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,67 @@ | ||
/* | ||
* Represents an alternative storage for browser that doesn't support localstorage. (i.e. Safari in private mode) | ||
* @implements Storage | ||
*/ | ||
export class AlternativeStorage implements Storage { | ||
private storageMap: any = {}; | ||
|
||
/* | ||
* Returns an integer representing the number of data items stored in the storageMap object. | ||
*/ | ||
get length() { | ||
return Object.keys(this.storageMap).length; | ||
}; | ||
|
||
/* | ||
* Remove all keys out of the storage. | ||
*/ | ||
clear(): void { | ||
this.storageMap = {}; | ||
} | ||
|
||
/* | ||
* Return the key's value | ||
* | ||
* @param key - name of the key to retrieve the value of. | ||
* @return The key's value | ||
*/ | ||
getItem(key: string): string | null { | ||
if (typeof this.storageMap[key] !== 'undefined' ) { | ||
return this.storageMap[key]; | ||
} | ||
return null; | ||
} | ||
|
||
/* | ||
* Return the nth key in the storage | ||
* | ||
* @param index - the number of the key you want to get the name of. | ||
* @return The name of the key. | ||
*/ | ||
key(index: number): string | null { | ||
return Object.keys(this.storageMap)[index] || null; | ||
} | ||
|
||
/* | ||
* Remove a key from the storage. | ||
* | ||
* @param key - the name of the key you want to remove. | ||
*/ | ||
removeItem(key: string): void { | ||
this.storageMap[key] = undefined; | ||
}; | ||
|
||
/* | ||
* Add a key to the storage, or update a key's value if it already exists. | ||
* | ||
* @param key - the name of the key. | ||
* @param value - the value you want to give to the key. | ||
*/ | ||
setItem(key: string, value: string): void { | ||
this.storageMap[key] = value; | ||
}; | ||
|
||
[key: string]: any; | ||
[index: number]: string; | ||
|
||
} |
Oops, something went wrong.