Use yeild* to call controlled actions

[MAILPOET-2681]
This commit is contained in:
Amine Ben hammou
2020-04-01 03:18:53 +02:00
committed by Veljko V
parent 0d0538705b
commit 2557586e86
2 changed files with 9 additions and 35 deletions

View File

@@ -118,43 +118,17 @@ export function* verifyPremiumKey(key: string) {
let pluginActive = res.meta.premium_plugin_active;
if (!pluginInstalled) {
yield updateKeyActivationState({
premiumStatus: 'valid_premium_plugin_being_installed',
premiumInstallationStatus: 'install_installing',
});
const call = yield {
type: 'CALL_API',
endpoint: 'premium',
action: 'installPlugin',
};
if (call && !call.success) {
yield updateKeyActivationState({ premiumInstallationStatus: 'install_installing_error' });
pluginInstalled = false;
} else {
pluginInstalled = true;
const actions = installPremiumPlugin();
let action = actions.next();
while (!action.done) {
yield action.value;
action = actions.next();
}
pluginInstalled = action.value;
}
if (pluginInstalled && !pluginActive) {
const isAfterInstall = !res.meta.premium_plugin_installed;
const doneStatus = isAfterInstall ? 'install_done' : 'activate_done';
const errorStatus = isAfterInstall ? 'install_activating_error' : 'activate_error';
yield updateKeyActivationState({
premiumStatus: 'valid_premium_plugin_being_activated',
premiumInstallationStatus: isAfterInstall ? 'install_activating' : 'activate_activating',
});
const call = yield {
type: 'CALL_API',
endpoint: 'premium',
action: 'activatePlugin',
};
if (call && !call.success) {
yield updateKeyActivationState({ premiumInstallationStatus: errorStatus });
pluginActive = false;
} else {
yield updateKeyActivationState({ premiumInstallationStatus: doneStatus });
pluginActive = true;
}
pluginActive = yield* activatePremiumPlugin(!res.meta.premium_plugin_installed);
}
if (pluginInstalled && pluginActive) {
@@ -206,5 +180,5 @@ export function* installPremiumPlugin() {
yield updateKeyActivationState({ premiumInstallationStatus: 'install_installing_error' });
return false;
}
return true;
return yield* activatePremiumPlugin(true);
}

View File

@@ -21,6 +21,7 @@
"noImplicitThis": false, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": false, /* Parse in strict mode and emit "use strict" for each source file. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": false, /* Report errors in .js files. */
@@ -35,7 +36,6 @@
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Additional Checks */