@adpt/cloud
Version:
AdaptJS cloud component library
57 lines • 2.37 kB
JavaScript
;
/*
* Copyright 2018-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 tslib_1 = require("tslib");
const core_1 = tslib_1.__importStar(require("@adpt/core"));
const stack_context_1 = require("./stack_context");
/** @beta */
class CFResourcePrimitive extends core_1.PrimitiveComponent {
constructor() {
super(...arguments);
this.deployedWhen = async (goalStatus, helpers) => {
const hand = this.props.cfStackHandle;
if (!hand) {
throw new Error(`CFResource must have a valid Handle ` +
`to its corresponding CFStack in props.cfStackHandle`);
}
if (!hand.target) {
throw new Error(`CFResource props.cfStackHandle does not ` +
`reference a valid Element`);
}
if (helpers.isDeployed(hand))
return true;
return core_1.waiting(`Waiting for CFStack to be ${goalStatus.toLowerCase()}`);
};
}
}
exports.CFResourcePrimitive = CFResourcePrimitive;
/** @beta */
function isCFResourcePrimitiveElement(val) {
return core_1.isFinalDomElement(val) && val.componentType === CFResourcePrimitive;
}
exports.isCFResourcePrimitiveElement = isCFResourcePrimitiveElement;
/** @beta */
function CFResource(props) {
const { handle: _h, cfStackHandle } = props, rest = tslib_1.__rest(props, ["handle", "cfStackHandle"]);
// Always call hook
let stackHand = core_1.useContext(stack_context_1.CFStackContext);
if (cfStackHandle)
stackHand = cfStackHandle;
return core_1.default.createElement(CFResourcePrimitive, Object.assign({ cfStackHandle: stackHand }, rest));
}
exports.CFResource = CFResource;
//# sourceMappingURL=CFResource.js.map