UNPKG

nuclear-instance-container

Version:

A nuclear-js module to save arbitrary objects as instances. To be used as a singleton registry for a nuclear-js app.

45 lines (37 loc) 1 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createModel; var _lodash = require('lodash.mapvalues'); var _lodash2 = _interopRequireDefault(_lodash); var _immutable = require('immutable'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Creates an immutable record instance from given simple interface instance. * * Example: * Turns * { * key: String, * shared: Boolean, * resolver: Function * } * to * { * key: '', * shared: false, * resolver: () => {} * } * * @public * @param {SimpleInterface} interface * @returns {immutable.Record} */ function createModel(_interface) { var contract = _interface.getContract(); var description = (0, _lodash2.default)(contract, function (Factory, key) { return Factory(); }); return (0, _immutable.Record)(description); }