UNPKG

@aeternity/aepp-sdk

Version:
103 lines (90 loc) 3.77 kB
import _path from "ramda/src/path"; import _flatten from "ramda/src/flatten"; import _identical from "ramda/src/identical"; import _uniqWith from "ramda/src/uniqWith"; import _without from "ramda/src/without"; import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator"; import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce"; import _Promise from "@babel/runtime-corejs3/core-js-stable/promise"; import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map"; /* * ISC License (ISC) * Copyright (c) 2018 aeternity developers * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ import stampit from '@stamp/it'; function asyncInit() { var _context; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var _ref = arguments.length > 1 ? arguments[1] : undefined, stamp = _ref.stamp, args = _ref.args, instance = _ref.instance; return _reduceInstanceProperty(_context = stamp.compose.deepConfiguration.AsyncInit.initializers).call(_context, /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(instance, init) { var ret; return _regeneratorRuntime.wrap(function _callee$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return _Promise.resolve(instance); case 2: instance = _context2.sent; if (!(typeof init === 'function')) { _context2.next = 8; break; } _context2.next = 6; return _Promise.resolve(init.call(instance, options, { stamp: stamp, args: args, instance: instance })); case 6: ret = _context2.sent; return _context2.abrupt("return", ret === undefined ? instance : ret); case 8: return _context2.abrupt("return", instance); case 9: case "end": return _context2.stop(); } } }, _callee); })); return function (_x, _x2) { return _ref2.apply(this, arguments); }; }(), instance); } var AsyncInit = stampit({ deepConf: { AsyncInit: { initializers: [] } }, composers: function composers(_ref3) { var stamp = _ref3.stamp, composables = _ref3.composables; var conf = stamp.compose.deepConfiguration.AsyncInit; conf.initializers = _without([asyncInit], _uniqWith(_identical, _flatten(_mapInstanceProperty(composables).call(composables, function (c) { return _path(['compose', 'deepConfiguration', 'AsyncInit', 'initializers'], c) || (c.compose || c).initializers || []; })))); stamp.compose.initializers = [asyncInit]; } }); export default AsyncInit; //# sourceMappingURL=async-init.js.map