Allow passing engine options in load() #141

Closed
elliottsj wants to merge 1 commit from engine-config-load into master
elliottsj commented 2016-05-31 20:10:39 +00:00 (Migrated from github.com)

For #140.

This backwards-compatible change allows you to pass options to the engine as part of the load() call, e.g.

const load = storage.createLoader(engine);
// ...
load(store, 'my-save-key', { foo: 'bar' });

For example, a localForage engine can be implemented like this:

// localForageEngine.js

import localforage from 'localforage';

export default function createEngine() {
  let key;
  let engineConfig;
  return {
    load(...engineOpts) {
      if (!engineConfig) {
        [key, engineConfig] = engineOpts;
        localforage.config(engineConfig);
      }
      return localforage.getItem(key);
    },

    save(state) {
      if (!engineConfig) {
        throw new Error('LocalForage is not configured; you must call `load(config)`');
      }
      return localforage.setItem(key, state);
    },
  };
}

For #140. This backwards-compatible change allows you to pass options to the engine as part of the `load()` call, e.g. ``` js const load = storage.createLoader(engine); // ... load(store, 'my-save-key', { foo: 'bar' }); ``` For example, a localForage engine can be implemented like this: ``` js // localForageEngine.js import localforage from 'localforage'; export default function createEngine() { let key; let engineConfig; return { load(...engineOpts) { if (!engineConfig) { [key, engineConfig] = engineOpts; localforage.config(engineConfig); } return localforage.getItem(key); }, save(state) { if (!engineConfig) { throw new Error('LocalForage is not configured; you must call `load(config)`'); } return localforage.setItem(key, state); }, }; } ```
michaelcontento commented 2016-06-08 13:41:14 +00:00 (Migrated from github.com)

For a full discussion about this feature please see #140

For a full discussion about this feature please see #140
elliottsj commented 2016-06-09 22:49:39 +00:00 (Migrated from github.com)

Closing as I found a better solution for my problem: https://github.com/michaelcontento/redux-storage/issues/140#issuecomment-225049708

Closing as I found a better solution for my problem: https://github.com/michaelcontento/redux-storage/issues/140#issuecomment-225049708

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MichaelContento/redux-storage!141
No description provided.