Callbacks are a great tool to achieve SRP. For ex. the following function is responsbile for submitting forms and nothing else.
// SRP
const submitForm = ({apiUrl, payload, onSuccess, onFailure}) => {
fetch(apiUrl, payload)
.then((res) => {| All Chrome Scripts here. |
| var filters = "" | |
| $('img').toArray().forEach(iterateImageElements.bind(this)); | |
| console.log(filters) | |
| function iterateImageElements(){ | |
| var _this = arguments[0]; | |
| filters += getImagePaths.apply(_this, arguments) + "\n"; | |
| } |
| var fileName = 'test-450.json'; | |
| var fileData; | |
| var savedFileEntry = {}; | |
| promise_getPersistentDirectoryEntry() | |
| .then(promise_fileEntry.bind(null, fileName, { create:false })) | |
| .then(save_fileEntry) | |
| .then(promise_file) | |
| .then(promise_fileContent) |
| // a sample array of items. | |
| const values = [ | |
| 'item1', | |
| 'item2' | |
| ] | |
| // checkValue(item) is an async that returns true or false. | |
| const promises = values.map(async(item) => checkValue(item).catch(err => err)) | |
| const results = await Promise.all(results) | |
| console.log(results); // ['true', 'false']; |
| const getIsDisabled = ({fromDate, toDate, selectedKey) => { | |
| let isDisabled = true; // set the initial value to true | |
| if(selectedKey === 'valueA') { | |
| isDisabled = false; | |
| } else if(selectedKey === 'valueB') { | |
| if(fromDate) { | |
| const isfromDateValid = moment(fromDate).isValid(); | |
| const isfromDateGreaterThanOrEqualToToday = moment().diff(fromDate) <= 0; | |
| if(isfromDateValid && isfromDateGreaterThanOrEqualToToday) { | |
| isDisabled = false |
486 ;486 2 numbers
| dscacheutil -flushcache; sudo killall -HUP mDNSResponder |