From dcdfc94cb39dfe2c39925a0145ffa45e2d061c30 Mon Sep 17 00:00:00 2001 From: Kumar Priyansh Date: Sat, 19 Jan 2019 12:37:14 +0530 Subject: Initial Upload via GIT --- .../node_modules/cordova-common/src/ActionStack.js | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 cordova/node_modules/cordova-common/src/ActionStack.js (limited to 'cordova/node_modules/cordova-common/src/ActionStack.js') diff --git a/cordova/node_modules/cordova-common/src/ActionStack.js b/cordova/node_modules/cordova-common/src/ActionStack.js new file mode 100755 index 0000000..6983c5c --- /dev/null +++ b/cordova/node_modules/cordova-common/src/ActionStack.js @@ -0,0 +1,85 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +/* jshint quotmark:false */ + +var events = require('./events'); +var Q = require('q'); + +function ActionStack () { + this.stack = []; + this.completed = []; +} + +ActionStack.prototype = { + createAction: function (handler, action_params, reverter, revert_params) { + return { + handler: { + run: handler, + params: action_params + }, + reverter: { + run: reverter, + params: revert_params + } + }; + }, + push: function (tx) { + this.stack.push(tx); + }, + // Returns a promise. + process: function (platform) { + events.emit('verbose', 'Beginning processing of action stack for ' + platform + ' project...'); + + while (this.stack.length) { + var action = this.stack.shift(); + var handler = action.handler.run; + var action_params = action.handler.params; + + try { + handler.apply(null, action_params); + } catch (e) { + events.emit('warn', 'Error during processing of action! Attempting to revert...'); + this.stack.unshift(action); + var issue = 'Uh oh!\n'; + // revert completed tasks + while (this.completed.length) { + var undo = this.completed.shift(); + var revert = undo.reverter.run; + var revert_params = undo.reverter.params; + + try { + revert.apply(null, revert_params); + } catch (err) { + events.emit('warn', 'Error during reversion of action! We probably really messed up your project now, sorry! D:'); + issue += 'A reversion action failed: ' + err.message + '\n'; + } + } + e.message = issue + e.message; + return Q.reject(e); + } + this.completed.push(action); + } + events.emit('verbose', 'Action stack processing complete.'); + + return Q(); + } +}; + +module.exports = ActionStack; -- cgit v1.2.3