Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / build / dist / new-forms / OneForm / renderInput.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const exotic_1 = require("exotic");
const inputs_1 = require("../inputs");
const deps_1 = require("../deps");
const PluginsContext_1 = require("../plugins/PluginsContext");
/**
 * @alias renderInputFromPluginContext
 * @todo @@perf
 */
exports.renderInput = (inputState, index) => (React.createElement(PluginsContext_1.PluginsContext.Consumer, { key: inputState.identifier + index + '-consumer' }, plugins => {
    if (process.env.NODE_ENV !== 'production') {
        if (Array.isArray(plugins) === false) {
            throw new TypeError('PluginsContext.Provider was not used - use it to provide the plugins used to render a form');
        }
    }
    const isSatisfiedBy = (Plugin) => {
        if (process.env.NODE_ENV !== 'production' && !Plugin) {
            console.error('plugins has an invalid entry: ');
            console.log(Plugin);
            return false;
        }
        else {
            return Plugin.isSatisfiedByProps(inputState);
        }
    };
    if (plugins.some(isSatisfiedBy)) {
        // console.debug('[renderInput]')
        const Found = plugins.find(isSatisfiedBy);
        /**
         * @todo this may cause updates when rendering...
         *       need to only `find` it once
         */
        if (exotic_1.isFunction(Found.defaultState)) {
            const pluginState = Found.defaultState(inputState);
            if (exotic_1.isFunction(pluginState.validator)
                && deps_1.DEFAULT_VALIDATOR.toString() !== inputState.validator.toString()
                && pluginState.validator.toString() !== inputState.validator.toString()) {
                delete pluginState.validator;
            }
            console.debug('[1form]:renderInput had defaultState - fn');
            inputState.merge(pluginState);
        }
        else if (exotic_1.isObj(Found.defaultState)) {
            console.debug('[1form]:renderInput had defaultState - obj');
            inputState.merge(Found.defaultState);
        }
        else {
            console.debug('[1form]:renderInput had no defaultProps');
        }
        // @todo why this type no like
        return React.createElement(Found, { state: inputState, key: inputState.identifier + index });
    }
    else {
        console.error('[1form]:renderInput did not find plugin');
        return (React.createElement(inputs_1.ObserverInput, { state: inputState, key: inputState.identifier + index }));
    }
}));
//# sourceMappingURL=renderInput.js.map