[Core] Bring in core bundle from sandbox
Bring in bundle platform/core from the sandbox branch, in preparation for clean up, tests, and integration. WTD-573
This commit is contained in:
53
platform/core/src/actions/ActionCapability.js
Normal file
53
platform/core/src/actions/ActionCapability.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining ActionCapability. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function ActionCapability(actionService, domainObject) {
|
||||
var self;
|
||||
|
||||
function getActions(context) {
|
||||
var baseContext = typeof context === 'string' ?
|
||||
{ key: context } :
|
||||
(context || {}),
|
||||
actionContext = Object.create(baseContext);
|
||||
|
||||
actionContext.domainObject = domainObject;
|
||||
|
||||
return actionService.getActions(actionContext);
|
||||
}
|
||||
|
||||
function performAction(context) {
|
||||
var actions = getActions(context);
|
||||
|
||||
return Promise.resolve(
|
||||
(actions && actions.length > 0) ?
|
||||
actions[0].perform() :
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
self = {
|
||||
invoke: function () {
|
||||
return self;
|
||||
},
|
||||
perform: performAction,
|
||||
getActions: getActions
|
||||
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
return ActionCapability;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user