Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Feature request: locker.getDriverName() #40

Open
andreaslarssen opened this issue Sep 5, 2017 · 0 comments
Open

Feature request: locker.getDriverName() #40

andreaslarssen opened this issue Sep 5, 2017 · 0 comments

Comments

@andreaslarssen
Copy link

Hi.

I just added my own custom driver that uses cookies for storage, and works fine for the most part. Some functionality in my app needs just a bit more space than cookies can handle, so I want to disable that functionality when user's using a browser that does not support localStorage, like Safari in private mode.

To keep from having to test everywhere if localStorage is available and / or manually set the proper driver, I chucked it all in my Locker extension:

app.config(['CookieStorageProvider', 'lockerProvider',
  function (CookieStorageProvider, lockerProvider) {
    var defaults = {
      driver: 'local',
      namespace: 'my.namespace',
      separator: '_',
      eventsEnabled: true,
      extend: {}
    };

    try {
      localStorage.setItem('localStorageTest', 'localStorageTest');
      localStorage.removeItem('localStorageTest');
      lockerProvider.defaults(defaults);
    } catch(e) {
      defaults.extend = {
        cookieStorage: CookieStorageProvider.get()
      };

      defaults.driver = 'cookieStorage';
      lockerProvider.defaults(defaults);
    }
  }
]);

I haven't quite figured out if Locker is meant to use whatever driver(s) are available, and switch between them, leaving it unnecessary and undesirable for developers to even know what happens behind the curtains other than setting desired driver (default). If so, this might not be the right approach, and the feature request redundant. If Locker, on the other hand, is supposed to use one driver at the time (unless explicitly switched), then it would be nice to be able to call something like locker.getDriverName(), that would return 'cookieStorage' in the case of Safari private mode etc. in my case.

I'm using the "private" locker._options.driver attribute to achieve this right now, but that's hardly the intention.

👍 Good or 👎 garbage?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant