Skip to content

Commit

Permalink
Filter undefined values in pre-config to avoid current values reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-eremin committed Jul 29, 2020
1 parent ebb955f commit b33cc3e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const defaultOptions = {
endpoint: null, // api endpoint url
smdUrl: null, // smd scheme url
headers: {}, // headers added to each request smdbox makes
selector: '#json-rpc-root', // element to which smdbox is inserted
selector: '#smdbox-root', // element to which smdbox is inserted
};
```
You can override any of this options to pre-fill project options.
Expand Down
20 changes: 10 additions & 10 deletions dist/app.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "smdbox",
"version": "1.0.3",
"version": "1.1.1",
"main": "src/index.jsx",
"repository": "https://gitlab.semrush.net/m.eremin/smdbox",
"repository": "https://github.com/semrush/smdbox",
"author": "Semrush",
"license": "MIT",
"scripts": {
Expand Down
9 changes: 1 addition & 8 deletions src/assets/html/index.dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
</head>
<body>
<!-- USE THIS BLOCK TO AUTO INIT SMDBOX WITHOUT CALLS <div id="json-rpc-root"></div>-->
<div id="smdbox-root"></div>
<script>
if (window.smdbox) {
window.smdbox({
selector: '#smdbox-root',
})
}
</script>
<div id="json-rpc-root"></div>
</body>
</html>
6 changes: 5 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import pickBy from 'lodash/pickBy';
import identity from 'lodash/identity';
import merge from 'lodash/merge';
import Application from 'containers/Application';
import { get as getStore } from 'helpers/session';
Expand Down Expand Up @@ -48,7 +50,9 @@ const init = (opts = {}) => {

getStore((storeData = {}) => {
// set preconfigured smdUrl, endpoint and headers from config
merge(storeData, { project: { smdUrl, endpoint, headers } });
// filter null values if some of settings are not defined, to avoid current values reset
const project = pickBy({ smdUrl, endpoint, headers }, identity);
merge(storeData, { project });
const store = configureStore(storeData);
renderApp(Application, store);
});
Expand Down

0 comments on commit b33cc3e

Please sign in to comment.