@adpt/cloud
Version:
AdaptJS cloud component library
47 lines • 1.92 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 tslib_1 = require("tslib");
const core_1 = require("@adpt/core");
const utils_1 = require("@adpt/utils");
const ld = tslib_1.__importStar(require("lodash"));
const env_1 = require("./env");
const defaultUseConnectToOptions = {
xform: (x) => x,
};
function calculateConnectToOptions(xformOrOptions) {
if (xformOrOptions == null)
return defaultUseConnectToOptions;
if (ld.isFunction(xformOrOptions))
return Object.assign({}, defaultUseConnectToOptions, { xform: xformOrOptions });
const noUndefOptions = ld.omitBy(xformOrOptions, ld.isUndefined);
return Object.assign({}, defaultUseConnectToOptions, noUndefOptions);
}
function useConnectTo(connectTo, xformOrOptions) {
const options = calculateConnectToOptions(xformOrOptions);
const xform = options.xform;
const noUndefXform = (e) => {
if (e === undefined)
return xform({});
return xform(e);
};
const connectEnvs = core_1.useAsync(() => utils_1.toArray(connectTo)
.map((h) => noUndefXform(core_1.callInstanceMethod(h, undefined, "connectEnv", options.scope))), []);
return env_1.mergeEnvPairs(...connectEnvs);
}
exports.useConnectTo = useConnectTo;
//# sourceMappingURL=ConnectTo.js.map