Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequireJS support - no exports? #3

Open
tommck opened this issue Jan 8, 2014 · 12 comments
Open

RequireJS support - no exports? #3

tommck opened this issue Jan 8, 2014 · 12 comments
Labels

Comments

@tommck
Copy link

tommck commented Jan 8, 2014

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
Copy link
Author

tommck commented Jan 8, 2014

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

@stevegreatrex
Copy link
Owner

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?

@tommck
Copy link
Author

tommck commented Jan 9, 2014

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

@stevegreatrex
Copy link
Owner

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.

@tommck
Copy link
Author

tommck commented Jan 9, 2014

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

@stevegreatrex
Copy link
Owner

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

@tommck
Copy link
Author

tommck commented Jan 9, 2014

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

@tommck
Copy link
Author

tommck commented Jan 21, 2014

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

@kingsleyh
Copy link

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.

@MarcoGaribaldi
Copy link

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.

@oliverkane
Copy link

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

@stevegreatrex
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants