tymondesigns/angular-locker

[Feature Request] Add where method to find value location

Open

#20 opened on Jun 24, 2015

View on GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (41 forks)github user discovery
Hacktoberfest

Repository metrics

Stars
 (313 stars)
PR merge metrics
 (PR metrics pending)

Description

querying objects in locker should query both session, and local unless specified. If I say locker.has('user') I would expect that to return true if there is an object called 'user' in either the local or session storage.

Example use case:

app.controller('LoginCtrl', [
  '$scope', 'locker', function($scope, locker) {
    $scope.email = '';
    $scope.password = '';
    $scope.rememberMe = false;
    $scope.signIn = void 0;
    $scope.user = {
      email: '',
      password: ''
    };
    $scope.rememberMe = false;
    return $scope.signIn = function() {
      if ($scope.rememberMe) {
        return locker.driver('local').put('user', $scope.user);
      } else {
        return locker.driver('session').put('user', $scope.user);
      }
    };
  }
]);

Here I allow the user to define which locker they use. Specifying driver on locker.put makes sense, but now later through out my application I either need to create a $rootScope variable to tell me which locker to use or I need to do this all over the place:

if (locker.driver('local').has('user')) {
      return locker.driver('local').get('user');
    } else {
      return locker.get('user');
}

Ideally both locker.has and locker.get would query both lockers, unless I specifically say locker.driver('local').has or locker.driver('local').get

Contributor guide