Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
patch: function(patch) {
if(!this._shadow) {
return;
}
var metadata = this.metadata;
this._shadow = metadata.patch(this._shadow, patch);
var identify = this.metadata.id;
var client = this._client;
var seen = {};
// Need a better strategy here for arrays. Using ids
// would work out fine regardless.
return when.reduce(patch, function(previousRequest, change) {
/*jshint maxcomplexity:6*/
var entity, segments;
var p = change.path;
segments = p.split(change.path);
p = segments[0];
if(seen[p]) {
return;
}
seen[p] = 1;
if(segments.length === 1) {
if(change.op === 'add') {
entity = metadata.getValue(data, p);
function preSaveHook(editor) {
sort();
//Call each of the handlers one by one in sequence until one of them
//rejects. The preSaveHook returns a promise that rejects if any
//of the promises where rejected.
return when.reduce(preSaveHandlers,
function (acc, handler, i) {
return when(acc, function () {
//console.log('handle index: '+i);
return handler(editor, editor.getFilePath());
});
},
null //IMPORTANT: may be anything except undefined...
// because reduce behaves differently if no inital value is suplied!
);
}
function doP160(date) {
// return a promise for a boolean which is false if data was processed, and true if data was not available
// i.e., true == we are done.
// CONSIDER: This function's behavior is subtle and confusing. Improve.
var promises = [doP160Page(1, date), doP160Page(2, date)];
return when.reduce(
promises,
function(current, value) {
return current && !value;
},
true);
}
run(compilation, done) {
if (this.addDataTo.dato && !this.aggressiveRefresh) return done()
return W.all([
this.client.site.find(),
W.reduce(
this.models,
(memo, model) => {
// format options
const options = { allPages: true }
const params = { version: this.drafts ? 'latest' : 'published' }
if (model.ids) {
params['filter[ids]'] = model.ids
}
if (model.query) {
params['filter[query]'] = model.query
}
if (model.offset) {
params['page[offset]'] = model.offset
}
if (model.limit) {
params['page[limit]'] = model.limit
.then(function () { // 串行 list 队列
return when.reduce(list, function (x, i) {
return task(i);
}, 1);
})
.then(function () { // 并行 tasks 队列
return api.listWebhooks().then(hooks => {
console.log('Found ' + hooks.length + ' hooks registered\n');
return when.reduce(hooks, (ignore, hook) => {
console.log('deleting ' + hook.id);
return api.deleteWebhook(hook.id);
});
});
}
return function (source, dest, data, type, api) {
return when.reduce(strategies,
function(result, strategy) {
var strategyResult = strategy(source, dest, data, type, api);
return api.isCanceled()
? when.reject(strategyResult)
: strategyResult;
},
data
).then(propagateSuccess, propagateSuccess);
}
.then(function(list) {
var subs = [];
list.forEach(function(item) {
subs.push(getChrootDiskUsage(path.join(loc, item)));
});
if (subs.length) {
return when.reduce(subs, function(sum, value) {
return sum += value;
});
} else return when.resolve(stats.size);
});
} else {
function reduceResolvers(resolvers, context, path) {
return when
.reduce(resolvers, function(result, resolver) {
return result ? result : resolver(context, path);
}, undefined);
}
return function (source, dest, data, type, api) {
when.reduce(strategies,
function(result, strategy) {
var strategyResult = strategy(source, dest, data, type, api);
return api.isCanceled()
? when.reject(strategyResult)
: strategyResult;
},
data
).always(function(result) { return result });
}