stevegreatrex / ko.plus

Awesome extensions to KnockoutJS
http://stevegreatrex.github.io/ko.plus
MIT License
34 stars 12 forks source link

RequireJS support - no exports? #3

Open tommck opened 10 years ago

tommck commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

stevegreatrex commented 10 years ago

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 commented 10 years ago

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

tommck commented 10 years ago

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

kingsleyh commented 10 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 8 years ago

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