@adpt/cloud
Version:
AdaptJS cloud component library
82 lines • 2.66 kB
JavaScript
;
/*
* Copyright 2019 Unbounded Systems, LLC
*
* Licensed 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@adpt/core");
const utils_1 = require("@adpt/utils");
const util_1 = require("util");
/**
* Type guard for {@link action.ShouldActDetail}.
* @public
*/
function isShouldActDetail(val) {
return utils_1.isObject(val) && typeof val.act === "boolean";
}
exports.isShouldActDetail = isShouldActDetail;
/**
* Transforms a {@link action.ShouldAct} into an {@link action.ShouldActDetail}.
* @internal
*/
function toDetail(val) {
return {
act: util_1.isBoolean(val) ? val : val.act,
detail: !util_1.isBoolean(val) && val.detail || "No action"
};
}
exports.toDetail = toDetail;
/**
* Component that can be inherited to perform actions during deploy
*
* @public
*/
class Action extends core_1.PrimitiveComponent {
/**
* Calculates whether or not any action is needed based on state/props/observation
*
* @returns false if no action needed, `{ act: true, detail: <user-facing description of action> }`.
*/
shouldAct(_op, _ctx) {
throw new Error(`Derived class '${this.constructor.name}' does not ` +
`implement required method 'shouldAct'`);
}
action(_op, _ctx) {
throw new Error(`Derived class '${this.constructor.name}' does not ` +
`implement required method 'action'`);
}
}
exports.Action = Action;
utils_1.tagConstructor(Action, "adapt");
/**
* Type guard for Action FinalDomElements.
* @internal
*/
function isActionFinalElement(val) {
return core_1.isFinalDomElement(val) &&
utils_1.isInstance(val.componentType.prototype, Action, "adapt");
}
exports.isActionFinalElement = isActionFinalElement;
/**
* Returns the component instance for an {@link action.Action} component.
* @internal
*/
function getActionInstance(el) {
const inst = el.instance;
if (utils_1.isInstance(inst, Action, "adapt"))
return inst;
return null;
}
exports.getActionInstance = getActionInstance;
//# sourceMappingURL=Action.js.map