У меня есть шаблон js promises, который я хочу определить для нескольких ключевых слов
Например, если я ставлю код вроде:
var deferred = Q.defer();
И в файле у меня есть также следующее значение
deferred.reject(err);
deferred.resolve();
return deferred.promise;
Полный код
ПРИМЕР 1
function writeError(errMessage) {
var deferred = Q.defer();
fs.writeFile("errors.log", errMessage, function (err) {
if (err) {
deferred.reject(err);
} else {
deferred.resolve();
}
});
return deferred.promise;
}
И я хочу, чтобы, если я поместил большой файл кода (как строку) , чтобы найти, что этот файл содержит шаблон
Другой пример
var d = Q.defer();/* или $q.defer */
И в файле у вас есть также следующее значение
d.resolve(val);
d.reject(err);
return d.promise;
Полный пример 2
function getStuffDone(param) {
var d = Q.defer(); /* or $q.defer */
Promise(function(resolve, reject) {
// or = new $.Deferred() etc.
myPromiseFn(param+1)
.then(function(val) { /* or .done */
d.resolve(val);
}).catch(function(err) { /* .fail */
d.reject(err);
});
return d.promise; /* or promise() */
}
Существуют открытые источники, которые можно использовать для проведения такого анализа (предоставить шаблон, и он найдет...)
Есть еще несколько сложных шаблонов с childProcess, но пока это нормально :)