In Magento 2's uiElement objects, one of the initialization methods is named initUnique

initialize: function () {

    return this;

The init functions usually setup some feature or magic in the uiElement objects. For example, the initLinks method sets up the imports/exports default.

However, after examining the source of initUnique

initUnique: function () {
    var update = this.onUniqueUpdate.bind(this),
        uniqueNs = this.uniqueNs;

    this.hasUnique = this.uniqueProp && uniqueNs;

    if (this.hasUnique) {
        this.source.on(uniqueNs, update, this.name);

    return this;

The onUniqueUpdate callback it sets up in the source property it binds and sets up if certain object properties are populated.

onUniqueUpdate: function (name) {
    var active = name === this.name,
        property = this.uniqueProp;


and the related setUnique method

#File: vendor/magento/module-ui/view/base/web/js/lib/core/element/element.js
setUnique: function () {
    var property = this.uniqueProp;

    if (this[property]()) {
        this.source.set(this.uniqueNs, this.name);

    return this;

It's still not clear what this "unique" object feature does, or how a uiElement object needs to be configured for the "unique" feature to take effect.

It seems related to the source property, which is populated during the call to initModules

initModules: function () {
    var modules = this.modules || {};

    _.each(modules, function (name, property) {
        this[property] = this.requestModule(name);
    }, this);

    if (!_.isFunction(this.source)) {
        this.source = registry.get(this.provider);

    return this;

but there's too many loose threads to know what, if anything, is being kept or made unique, or if "unique" is a red herring and this feature actually does something else.

I'm hoping someone else here knows and can shed some light on the matter with a plain english explanation of what this feature does in the UI Component system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.