Skip to content

Commit

Permalink
passing in custom storage to keep storage separate per tab
Browse files Browse the repository at this point in the history
  • Loading branch information
skevy committed Oct 2, 2015
1 parent 93fbe54 commit 1e4700b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion app/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default class App extends React.Component {
}
<GraphiQL
key={currentTabKey + currentTab.endpoint + JSON.stringify(currentTab.headers)}
storageKeyPrefix={`graphiql:${currentTabKey}`}
storage={getStorage(`graphiql:${currentTabKey}`)}
fetcher={this.graphQLFetcher} />
</div>
</div>
Expand Down Expand Up @@ -296,3 +296,19 @@ export default class App extends React.Component {
);
}
}

const _storages = {};

function _makeStorage(storageKey) {
return {
setItem: (key, val) => window.localStorage.setItem(`${storageKey}${key}`, val),
getItem: (key) => window.localStorage.getItem(`${storageKey}${key}`)
};
}

function getStorage(storageKey) {
if (!_storages[storageKey]) {
_storages[storageKey] = _makeStorage(storageKey);
}
return _storages[storageKey];
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"url": "https://github.com/skevy/graphiql-app/issues"
},
"dependencies": {
"graphiql": "^0.3.0",
"graphiql": "skevy/graphiql#redbox",

This comment has been minimized.

Copy link
@tinnou

tinnou Jan 11, 2016

thats breaks npm run build for me

"graphql": "^0.4.7",
"isomorphic-fetch": "^2.1.1",
"lodash": "^3.10.1",
Expand Down

0 comments on commit 1e4700b

Please sign in to comment.