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

Source: bop/js/api/BOPRegistry.js

define([
    'core/js/api/Implementations'
], function(
        Implementations
    ) {

    'use strict';

    /**
     * API object for (de)registering {@link bop/js/spi/BOP BOP} instances from/to Application Builder data model.
     *
     * @AbcsExtension stable
     * @version 17.1.1
     * @exports bop/js/api/BOPRegistry
     *
     * @constructor
     * @private
     *
     * @see {@link bop/js/spi/BOP BOP}
     *
     * @example
     * <caption>
     *  Typical implementation using {@link bop/js/api/BOPRegistry BOPRegistry} to register custom {@link bop/js/spi/BOP BOP} into Application Builder data model.
     * </caption>
     *
     * define([
     *     'bop/js/api/BOPRegistry',
     *     '{{package}}/js/CustomBOP'
     * ], function (
     *     BOPRegistry,
     *     CustomBOP
     * ) {
     *
     *     'use strict';
     *
     *     var CustomBOPExtension = function () {
     *     };
     *
     *     CustomBOPExtension.prototype.initialise = function () {
     *         var self = this;
     *         var bop = new CustomBOP();
     *         this._bop = bop;
     *
     *         return BOPRegistry.register(bop, self);
     *     };
     *
     *     CustomBOPExtension.prototype.destroy = function () {
     *         var self = this
     *         return BOPRegistry.deregister(self._bop, self).then(function() {
     *             self._bop = undefined;
     *         });
     *     };
     *
     *     CustomBOPExtension.prototype.generateRuntimeCode = function () {
     *         // Include your code which generates static RT code
     *     };
     *
     *     return AbcsLib.initSingleton(CustomBOPExtension);
     * });
     */
    var BOPRegistry = function () {
        AbcsLib.checkSingleton(BOPRegistry);
    };

    /**
     * Register a new instance of {@link bop/js/spi/BOP BOP} into the Application Builder data model.
     *
     * @AbcsExtension stable
     * @version 17.1.1
     *
     * @param {bop/js/spi/BOP} bop
     * @param {extensions.dt/js/spi/ExtensionManager} provider - An instance of the {@link extensions.dt/js/spi/ExtensionManager ExtensionManager} which calls this method.
     * @returns {Promise<bop/js/spi/BOP>} - Promise of {@link bop/js/spi/BOP BOP} properly registered into Application Builder data model.
     */
    /*
     * If you're calling this method from ABCS codebase you need to pass
     * the wrapping BOP Shareable object instead of the ExtensionManager
     * as the second parameter despite what the public documentation says.
     */
    BOPRegistry.prototype.register = function () {
        var impl = getImplementation();
        return impl.register.apply(impl, arguments);
    };

    /**
     * Deregister existing instance of {@link bop/js/spi/BOP BOP} from Application Builder data model.
     *
     * @AbcsExtension stable
     * @version 17.1.1
     *
     * @param {bop/js/spi/BOP} bop
     * @param {extensions.dt/js/spi/ExtensionManager} provider - An instance of the {@link extensions.dt/js/spi/ExtensionManager ExtensionManager} which calls this method.
     * @returns {Promise<bop/js/spi/BOP>} - Promise of {@link bop/js/spi/BOP BOP} properly de-registered from Application Builder data model.
     */
    BOPRegistry.prototype.deregister = function () {
        var impl = getImplementation();
        return impl.deregister.apply(impl, arguments);
    };

    function getImplementation() {
        return Implementations.getImplementation('BOPRegistry');
    }

    return AbcsLib.initSingleton(BOPRegistry);
});