3

What I need to do is subscribe to another file / object via knockout js and require js.

For example I have in File1.js:

define(
[
    '/path/to/some/component',
    'ko'
],
function (Component, ko) {
    "use strict";
    return Component.extend({

        // this is the var that I need to subscribe to in File2
        somevar: ko.observable(null);

        // I have an event that triggers this method in another 
        // external file that sets somevar
        myEvent: function(value){
           somevar(value);
        }
   });
});

and in file2.js I need to do something like

define(
[
    '/path/to/some/component',
    '/path/to/file#1',
    'ko'
],
function (Component, File1, ko) {
    "use strict";
    return Component.extend({

        // set a new observable var in file 2
        subscribeVar: ko.observable(null);

        initialize : function(){

            // and subscribe to the change in value of the var in 
            // file 1
            File1.somevar() .subscribe(function(anotherValue){
                // here I want to execute my logic but the    
                // illustrated method of doing this is not working.
            }, this);
        },
   });
});
1
  • I had the same issue, it helped me: this
    – OleksaNdr
    Commented Aug 17, 2017 at 13:44

1 Answer 1

0

I used this construction to call other uiComponent

define([
    ...
    'uiRegistry',
], function (..., registry) {
    'use strict';

    ...
        let callback = function (component) {
            component.anyFuncFromAnotherComponent;
        };
        registry.get('ComponentName', callback);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.