const API = require('./mock-api');
const EventEmitter = require('events');
module.exports = class Search extends EventEmitter {
constructor() {
super();
}
async searchCount(term) {
if (!term) {
this.emit(
'SEARCH_ERROR',
{ message: 'INVALID_TERM', term }
);
return;
}
this.emit('SEARCH_STARTED', term);
try {
const count = await API.countMatches(term);
this.emit('SEARCH_SUCCESS', { term, count });
} catch (error) {
this.emit('SEARCH_ERROR', { term, message: error.message });
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter