Skip to content

Commit

Permalink
add useToast for easier enable disable
Browse files Browse the repository at this point in the history
  • Loading branch information
viankakrisna committed May 31, 2017
1 parent a86040a commit 0ebe353
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/react-scripts/template/src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import Toast from './Toast';

const useToast = true;
const domId = 'create-react-app-toast';
let dom = document.getElementById(domId);

Expand All @@ -20,13 +21,17 @@ if (!dom) {
document.body.appendChild(dom);
}

function renderToast(message) {
ReactDOM.render(
<Toast timeout={3000}>
{message}
</Toast>,
dom
);
function showMessage(message) {
if (useToast) {
ReactDOM.render(
<Toast timeout={3000}>
{message}
</Toast>,
dom
);
} else {
console.log(message);
}
}

export default function register() {
Expand All @@ -45,12 +50,12 @@ export default function register() {
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
renderToast('New content is available. Please refresh.');
showMessage('New content is available. Please refresh.');
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
renderToast('Content is cached for offline use.');
showMessage('Content is cached for offline use.');
}
}
};
Expand All @@ -61,7 +66,7 @@ export default function register() {
});
});
} else {
renderToast('Development mode started.');
showMessage('Development mode started.');
}
}

Expand Down

0 comments on commit 0ebe353

Please sign in to comment.