Answer the question
In order to leave comments, you need to log in
What pattern to use when designing multiple search?
Hello.
I am writing a search engine that will search for products in several databases and return the search result. The trick is that product catalogs have different fields (that's right!), but as a result, you need to display everything in the same structure. Sql queries are useless, they have nothing to do with it.
Help is needed only in choosing a pattern.
Answer the question
In order to leave comments, you need to log in
The Adapter pattern allows the design process to ignore possible differences in the interfaces of existing classes. If there is a class that has the required methods and properties (at least conceptually), then if necessary, you can always use the Adapter pattern to bring its interface to the desired form.
setTimeout ? ;-)
var now = +new Date();
console.log(now);
setTimeout(function() {
var future = +new Date();
console.log(future);
}, 5000); // Время в милисекундах, 1 сек = 1000 мсек
Is that a plugin?
function timer (delta, step) {
var count = 0;
(function t () {
if (count < step) {
console.log(count);
count++;
setTimeout(t, delta);
} else {
console.log(count, 'end');
}
})();
}
timer(1000, 5);
.factory('countdown', function($q, $interval) {
return function(to) {
var d = $q.defer();
var elapsed = 0;
var intervalId = $interval(function() {
elapsed += 1;
d.notify(elapsed);
if(Date.now() >= to) {
$interval.cancel(intervalId);
d.resolve();
}
}, 1000);
return d.promise;
};
});
If the accuracy is not important, then you can use the options given above
For after a few hours without reloading the page, the timer will lag behind for a time from one second to several minutes. Depends on the computer.
And if you need accuracy, then be sure to check against the current timestamp and adjust setInterval.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question