How to override dojo's domReady

我的梦境 提交于 2020-01-07 06:58:12

问题


I want to override dijit._CssStateMixin's domReady() method. Is there any way to override that instead of changing the listener mechanism in Dojo.

I tried overriding _cssMouseEvent() method in simple javascript, but it still does invoke dijit's _cssMouseEvent() from domReady().

I have tried following approach:

 dojoConfig = {
        map: {
            'dijit/_CssStateMixin': {
                    'dojo/domReady': 'app/noop'
            }
    }
}; 

I have added 'app' folder and then 'noop.js' inside that. noop.js has nothing in it:

    define([], function () {
    return function () {};
});

Even after this I can see that dijit.js's _CssStateMaxin domReady() getting called from listener.apply (code snippet pasted below)

var addStopImmediate = function(listener){
        return function(event){
            if(!event.immediatelyStopped){// check to make sure it hasn't been stopped immediately
                event.stopImmediatePropagation = stopImmediatePropagation;
                return listener.apply(this, arguments);
            }
        };
    }

回答1:


If your ultimate goal is to prevent the domReady callback in dijit/_CssStateMixin from running, your simplest bet is likely to re-map dojo/domReady to a different module that doesn't call the callback at all, when loaded via dijit/_CssStateMixin.

NOTE: Stripping out these handlers might have adverse visual effects on Dijit widgets which inherit _CssStateMixin, since it may hinder the application of Dijit CSS classes related to hover and focus. But if your concern is that _CssStateMixin is hampering performance, it may at least be worth a try to confirm or deny your suspicion.

First we have to create a simple module that returns a function that does nothing, which we will later substitute for dojo/domReady when loaded by dijit/_CssStateMixin, so that it can still call domReady but it won't execute the callback it passes.

For simplicity's sake I'll assume you already have a custom package that you can easily add a module to; for this example I'll assume it's called app. Let's create app/noop:

define([], function () {
    return function () {};
});

Now let's configure the loader to map app/noop in place of dojo/domReady specifically when loaded by dijit/_CssStateMixin:

var dojoConfig = {
    ...,
    map: {
            'dijit/_CssStateMixin': {
                    'dojo/domReady': 'app/noop'
            }
    },
    ...
};

Now the offending domReady callback should no longer be run.

If you're curious about map, you can read more about it in this SitePen FAQ.



来源:https://stackoverflow.com/questions/27945875/how-to-override-dojos-domready

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!