3

I'm following magento 2 official documentation to create my checkout step. I'm very new to knockoutjs, requirejs, js components which are massively used in magento 2, specially in checkout.

I'm struggling to unerstand the concept of mixins, extending and overriding js in magento.

I have seen somewhere earlier map was used to override js file. Now here mixins is used and seem to me to serve similar purpose.

In that documentation in this code section of viewModel:

define(
    [
        'ko'
    ], function (ko) {
        'use strict';

        var mixin = {

            initialize: function () {
                this.visible = ko.observable(false); // set visible to be initially false to have your step show first
                this._super();

                return this;
            }
        };

        return function (target) {
            return target.extend(mixin);
        };
    }
);

target is passed to a function, which is returned from the viewModel, at last, it further extends itself with mixin model. I'm confused here as well, where does target come from and what is being returned actually.

In short, my question is what is the difference between mixin and map, and explanation to the viewModel.

  • 1
    map overriding core file and use of mixins is you can change in any function/method and only override that require code. – Dhaduk Mitesh Oct 24 '18 at 11:07
  • 2
    When your requirement is to include something in core file then use of mixins. – Dhaduk Mitesh Oct 24 '18 at 11:09

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.