ko.plus icon indicating copy to clipboard operation
ko.plus copied to clipboard

RequireJS support - no exports?

Open tommck opened this issue 11 years ago • 12 comments

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?

tommck avatar Jan 08 '14 17:01 tommck

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

tommck avatar Jan 08 '14 18:01 tommck

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?

stevegreatrex avatar Jan 09 '14 18:01 stevegreatrex

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')

tommck avatar Jan 09 '14 18:01 tommck

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.

stevegreatrex avatar Jan 09 '14 18:01 stevegreatrex

That would be cool. For now, I have to rip apart the files to use the command object

tommck avatar Jan 09 '14 19:01 tommck

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

stevegreatrex avatar Jan 09 '14 19:01 stevegreatrex

Either way, I have to custom modify the code to wrap it up into a module :-(

tommck avatar Jan 09 '14 21:01 tommck

Oh, and ko.command.js has a dependency on ko.loadingWhen.js too

tommck avatar Jan 21 '14 21:01 tommck

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.

kingsleyh avatar Mar 29 '14 10:03 kingsleyh

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.

MarcoGaribaldi avatar Jan 06 '15 14:01 MarcoGaribaldi

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);

oliverkane avatar Apr 21 '15 17:04 oliverkane

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

stevegreatrex avatar Jan 14 '16 17:01 stevegreatrex