FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(application-settings): implemented allKeys method by surdu · Pull Request #6371 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
Expand Up @@ -112,6 +112,17 @@ export var testFlush = function () {
TKUnit.assert(appSettings.hasKey(stringKey), "There is no key: " + stringKey);
};

export var testAllKeys = function () {
appSettings.setString(stringKey, "String value");
appSettings.setBoolean(boolKey, true);
appSettings.setNumber(numberKey, 22);

var allKeys = appSettings.getAllKeys();
TKUnit.assert(allKeys.indexOf(stringKey) !== -1, `${stringKey} is missing from .allKeys()`);
TKUnit.assert(allKeys.indexOf(boolKey) !== -1, `${boolKey} is missing from .allKeys()`);
TKUnit.assert(allKeys.indexOf(numberKey) !== -1, `${numberKey} is missing from .allKeys()`);
}

export var testInvalidKey = function () {
try {
appSettings.hasKey(undefined);
Expand Down
This file contains hidden or 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
Expand Up @@ -83,3 +83,15 @@ export function clear(): void {
export var flush = function (): boolean {
return sharedPreferences.edit().commit();
}

export function getAllKeys(): Array<string> {
var mappedPreferences = sharedPreferences.getAll();
var iterator = mappedPreferences.keySet().iterator();
var result = [];
while (iterator.hasNext()) {
let key = iterator.next();
result.push(key);
}

return result;
}
This file contains hidden or 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
Expand Up @@ -67,3 +67,9 @@ export function clear(): void;
* @return {boolean} flag indicating if changes were saved successfully to disk.
*/
export function flush(): boolean;

/**
* Get all stored keys
* @return Array containing all stored keys
*/
export function getAllKeys(): Array<string>;
This file contains hidden or 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
Expand Up @@ -65,3 +65,7 @@ export var clear = function (): void {
export var flush = function (): boolean {
return userDefaults.synchronize();
}

export function getAllKeys(): Array<string> {
return utils.ios.collections.nsArrayToJSArray(userDefaults.dictionaryRepresentation().allKeys);
}

Back | FazBrowse Home | New Git URL