mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-08-08 03:54:35 +02:00
more progress promise chain
This commit is contained in:
parent
f6da982887
commit
91555e9bf9
1 changed files with 27 additions and 7 deletions
|
@ -9,22 +9,32 @@ var _ = require('underscore');
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
var intl = require('../intl');
|
var intl = require('../intl');
|
||||||
var prompt = require('prompt');
|
var prompt = require('prompt');
|
||||||
|
prompt.start();
|
||||||
|
|
||||||
var shouldBegin = Q.defer();
|
var shouldBegin = Q.defer();
|
||||||
var translateQueue = [];
|
var translateQueue = [];
|
||||||
var outputLocale = 'pirate';
|
var outputLocale = 'pirate';
|
||||||
|
|
||||||
var schema = {
|
var titleSchema = {
|
||||||
properties: {
|
properties: {
|
||||||
translation: {
|
title: {
|
||||||
message: 'What is the best translation for that title?'
|
message: 'What is the best translation for that title?'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var translate = function(context, path, key, blob) {
|
var aboutSchema = {
|
||||||
|
properties: {
|
||||||
|
about: {
|
||||||
|
message: 'What is the best translation for that about section?'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var translate = function(context, path, key, blob, schema) {
|
||||||
translateQueue.push({
|
translateQueue.push({
|
||||||
context: context,
|
context: context,
|
||||||
|
schema: schema,
|
||||||
path: path,
|
path: path,
|
||||||
key: key,
|
key: key,
|
||||||
blob: blob
|
blob: blob
|
||||||
|
@ -52,8 +62,7 @@ var processLevelIndex = function() {
|
||||||
'For the level sequence "' + name + '",',
|
'For the level sequence "' + name + '",',
|
||||||
'the about section is:',
|
'the about section is:',
|
||||||
'~~"' + about + '"',
|
'~~"' + about + '"',
|
||||||
'',
|
''
|
||||||
'What is the best translation for the about section?'
|
|
||||||
].join('\n');
|
].join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,13 +158,16 @@ var collectInput = function(cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var popTranslateQueue = function(queueObj) {
|
var popTranslateQueue = function(queueObj) {
|
||||||
|
var defer = Q.defer();
|
||||||
printSeparator();
|
printSeparator();
|
||||||
printContext(queueObj);
|
printContext(queueObj);
|
||||||
|
|
||||||
collectInput(function(input) {
|
collectInput(function(input) {
|
||||||
console.log(input);
|
console.log(input);
|
||||||
outputTranslation(queueObj, input);
|
outputTranslation(queueObj, input);
|
||||||
|
defer.resolve();
|
||||||
});
|
});
|
||||||
|
return defer.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
var appendLineAfterNeedleToFile = function(path, needle, line) {
|
var appendLineAfterNeedleToFile = function(path, needle, line) {
|
||||||
|
@ -219,8 +231,16 @@ var outputTranslation = function(queueObj, input) {
|
||||||
|
|
||||||
shouldBegin.promise
|
shouldBegin.promise
|
||||||
.then(function() {
|
.then(function() {
|
||||||
popTranslateQueue(translateQueue[0]);
|
// the tricky thing here is that we need to make a chain of promises
|
||||||
//_.each(translateQueue, popTranslateQueue);
|
var popChain = Q.defer();
|
||||||
|
var promise = popChain.promise;
|
||||||
|
_.each(translateQueue, function(queueItem) {
|
||||||
|
promise = promise.then(function() {
|
||||||
|
return popTranslateQueue(queueItem);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
popChain.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue