ko.plus
ko.plus copied to clipboard
RequireJS support - no exports?
It seems that the RequireJS support that's currently in the code supports retrieving knockout's "ko" variable through requireJS, but it doesn't seem to export its own variable.
(basically, it only adds things to the "ko" variable, it doesn't export anything)
So, I am unaware how to use this in a Durandal app I'm writing.
Can you tell me how to handle this?
additional info: Even the unit tests aren't using require to grab ko.plus stuff
From the ko.command tests .html file:
<script src="../src/ko.command.js"></script>
<script src="../src/ko.editable.js"></script>
<script src="../Scripts/require.js" type="text/javascript"></script>
the test code should be able to do a
var koCommand = require('kocommand")
or something like that
To be honest I've only ever used it with knockout so have only needed to populate the ko
object.
Which elements are you trying to use without knockout? ko.command
?
I'm not trying to use it without Knockout, I'm trying to use it without Knockout being GLOBAL.
The way it is now, "command" does not get added to the "ko" that's retrieved by other modules with require('knockout')
Ah yes, I've seen similar problems on knockout.validation
. The build process for this library needs revisiting in any case so maybe I can put in some real support for requirejs - it's really just tacked on at the minute.
That would be cool. For now, I have to rip apart the files to use the command object
Or just grab the original source for ko.command on its own from https://github.com/stevegreatrex/ko.plus/blob/master/src/ko.command.js
Either way, I have to custom modify the code to wrap it up into a module :-(
Oh, and ko.command.js has a dependency on ko.loadingWhen.js too
Hi
I've hacked up a version that works with Durandal.js https://github.com/kingsleyh/ko.plus/blob/master/dist/ko.plus.js
It's not tested but seems to work for me.
Thanks a lot @kingsleyh for hacking a version of ko.plus. I have been banging my head against a wall trying to make ko.plus work with require.js without luck.
Another thing those in this group could try is depart from the strict RequiresJS pattern, and allow a few globals. In my case, I include several scripts (mostly the ones that don't play well with RequiresJS) before Require is included on the page.
From there, just add a few shims in your main config file like the below and your app will happily work as if these globals were modules.
define('jquery', function () { return jQuery; });
define('knockout', ko);
Reviving this as it should really be fixed! The current version returns the ko
object from the require definition; is that sufficient to work with Durandal?
The other option would be to return an object with the command
, editable
etc. functions exposed instead of ko
.
Thoughts? Suggestions