-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
81 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
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,38 @@ | ||
export class FallbackStorage implements Storage { | ||
private valuesMap = new Map(); | ||
|
||
getItem(key) { | ||
const stringKey = String(key); | ||
if (this.valuesMap.has(key)) { | ||
return String(this.valuesMap.get(stringKey)); | ||
} | ||
return null; | ||
} | ||
|
||
setItem(key, val) { | ||
this.valuesMap.set(String(key), String(val)); | ||
} | ||
|
||
removeItem(key) { | ||
this.valuesMap.delete(key); | ||
} | ||
|
||
clear() { | ||
this.valuesMap.clear(); | ||
} | ||
|
||
key(i) { | ||
if (arguments.length === 0) { | ||
// this is a TypeError implemented on Chrome, Firefox throws Not enough arguments to Storage.key. | ||
throw new TypeError( | ||
"Failed to execute 'key' on 'Storage': 1 argument required, but only 0 present." | ||
); | ||
} | ||
const arr = Array.from(this.valuesMap.keys()); | ||
return arr[i]; | ||
} | ||
|
||
get length() { | ||
return this.valuesMap.size; | ||
} | ||
} |
Oops, something went wrong.