Skip to content

Commit

Permalink
minor refactoring in sendWeb.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-friedl committed Aug 2, 2019
1 parent 6b48ba4 commit a160ed7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 78 deletions.
112 changes: 39 additions & 73 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.3",
"husky": "^3.0.1",
"husky": "^3.0.2",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^6.2.0",
"opn-cli": "^3.1.0",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.1",
"release-it": "^12.3.4",
"release-it": "^12.3.5",
"sinon": "^1.17.7",
"sinon-chai": "^3.3.0"
},
Expand Down
8 changes: 5 additions & 3 deletions src/sendWeb.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const webPush = require('web-push');
const { is, unless, assoc } = require('ramda');
const { WEB_METHOD } = require('./constants');

const stringify = unless(is(String), JSON.stringify);

const sendWebPush = async (regIds, data, settings) => {
const payload = typeof data === 'string' ? data : JSON.stringify(data);
const payload = stringify(data);
const promises = regIds.map(regId =>
webPush
.sendNotification(regId, payload, settings.web)
Expand Down Expand Up @@ -36,8 +39,7 @@ const sendWebPush = async (regIds, data, settings) => {
failure: acc.failure + current.failure,
message: [...acc.message, ...current.message],
}));
reduced.method = WEB_METHOD;
return reduced;
return assoc('method', WEB_METHOD, reduced);
};

module.exports = sendWebPush;

0 comments on commit a160ed7

Please sign in to comment.