JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Source: components.dt/js/spi/registration/GeneratorProvider.js

define([], function () {

    'use strict';

    /**
     * Provider interface returning instances of component view {@link components.dt/js/spi/generators/Generator generators}.
     * Registers into ABCS with the {@link components.dt/js/api/ComponentProviderRegistry Component Registration API}.
     *
     * <p>Generator is called when the ABCS {@link pages.dt/js/api/View view model}
     * is rendered into HTML elements which browser understands. The generator
     * tells ABCS how to built the HTML element for a given view.</p>
     *
     * <p>Implement this to build your component's HTML tree from its views.
     * {@link components.dt/js/spi/registration/GeneratorProvider#getGenerator GeneratorProvider.getGenerator} should
     * return a generator for all views the component owns.</p>
     *
     * <p>When building a DOM element for a view ABCS iterates over registered
     * generator providers and builds the view with the first generator returned
     * from {@link components.dt/js/spi/registration/GeneratorProvider#getGenerator GeneratorProvider.getGenerator}.<br>
     * That means your provider may be asked to return a generator for an unrelated
     * view in which case you just return <code>undefined</code> and the ABCS will
     * continue searching for the proper generator.</p>
     *
     * @AbcsExtension stable
     * @exports components.dt/js/spi/registration/GeneratorProvider
     * @constructor
     * @private
     * @version 16.3.5
     * @example <caption>An example of a component view generator provider.</caption>
     * define([
     *    'myComponent/MyGenerator'
     * ], function (
     *    Generator
     *    ) {
     *
     *    'use strict';
     *
     *    var GeneratorProvider = function () {
     *    };
     *
     *    GeneratorProvider.prototype.getGenerator = function (view) {
     *        if (view.getType() === 'my-view-type' || view.getType() === 'my-other-view-type') {
     *            // return a generator instance understanding and capable of
     *            // building views of type 'my-view-type' and 'my-other-view-type'
     *            return new Generator();
     *        }
     *    };
     *
     *    return new GeneratorProvider();
     *
     * });
     * @see {@link components.dt/js/api/ComponentProviderRegistry Component Registration API}
     * @see {@link components.dt/js/spi/generators/Generator Generator SPI}
     * @see {@link components.dt/js/spi/generators/Generator Generator implementation example}
     */
    var GeneratorProvider = function() {
        AbcsLib.checkThis(this);
    };

    /**
     * Gets view generator instance rendering the DOM tree for the component views.
     *
     * <p><strong>Must</strong> be implemented and return an instance of {@link components.dt/js/spi/generators/Generator view generator}
     * the component owns. If your component does not know how to build the view
     * then return <code>undefined</code> and ABCS will try to find another generator
     * that can build the view.</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     * @param {pages.dt/js/api/View} view currently processed view.
     * @returns {components.dt/js/spi/generators/Generator|undefined} view generator instance or <code>undefined</code> if
     * the component does not own the view (does not know how to build its {@link pages.dt/js/api/View.getType view type}).
     */
    GeneratorProvider.prototype.getGenerator = function (/*view*/) {};

    return GeneratorProvider;

});