Always require a plugin to be loaded

Posted by axon on Stack Overflow See other posts from Stack Overflow or by axon
Published on 2014-08-20T15:33:35Z Indexed on 2014/08/20 16:21 UTC
Read the original article Hit count: 213

Filed under:
|
|

I am writing an application with RequireJS and Knockout JS. The application includes an extension to knockout that adds ko.protectedObservable to the main knockout object. I would like this to always be available on the require'd knockout object, and not only when I specify it in the dependencies. I could concat the files together, but that seems that it should be unnecessary.

Additionally, I can put knockout-protectedObservable as a dependency for knockout in the requirejs shim configuration, but that just leads to a circular dependency and it all fails to load.

Edit: I've solved me issue, but seems hacky, is there a better way?

-- Main.html

<script type="text/javascript" src="require.js"></script>
<script type="text/javascript">
    require(['knockout'], function(ko) {
        require(['knockout-protectedObservable']);
    });
</script>

-- knockout-protectedObservable.js

define(['knockout'], function(ko) {
    ko.protectedObservable = { ... };
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about knockout.js