Created
November 26, 2015 16:17
-
-
Save codeincontext/286e3cf5eca3c9a2e222 to your computer and use it in GitHub Desktop.
An ngCordova mock for the keychain that persists values with localstorage
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
| /** | |
| * Overriding the keychain ngCordovaMock to use localStorage | |
| **/ | |
| angular.module('ngCordovaMocks') | |
| .factory('$cordovaKeychain', ['$q', function ($q) { | |
| console.log('persistent keychain mock loaded') | |
| return { | |
| getForKey: function (key, serviceName) { | |
| // note: this implementation doesn't fail on an invalid servicename | |
| var key = 'keychain:' + serviceName + ':' + key; | |
| return $q.when(localStorage[key]); | |
| }, | |
| setForKey: function (key, serviceName, value) { | |
| var key = 'keychain:' + serviceName + ':' + key; | |
| localStorage[key] = value; | |
| return $q.when(); | |
| }, | |
| removeForKey: function (key, serviceName) { | |
| var key = 'keychain:' + serviceName + ':' + key; | |
| delete localStorage[key]; | |
| return $q.when(); | |
| } | |
| }; | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment