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

Add support for the Asynchronous Module Definition (AMD) and require.js #105

Merged
merged 23 commits into from
Feb 21, 2015

Conversation

jcbrand
Copy link
Contributor

@jcbrand jcbrand commented Feb 4, 2015

This pull request adds support for AMD which allows better integration with projects that use require.js for module and loading and dependency management.

The strophe.js file as well as the files under ./src/ should all still work in the traditional non-AMD usecases.

All tests pass and I also tested both the AMD and non-AMD usecases with converse.js

See #29

@jcbrand jcbrand changed the title Add support for the Asynchronous Module Definition (AMD) and require.js (updates #29) Add support for the Asynchronous Module Definition (AMD) and require.js Feb 4, 2015
Gordin added a commit that referenced this pull request Feb 21, 2015
Add support for the Asynchronous Module Definition (AMD) and require.js
@Gordin Gordin merged commit 6fca47a into master Feb 21, 2015
@Gordin Gordin deleted the amd-merge branch February 21, 2015 01:19
@benlangfeld
Copy link
Contributor

Use in a non-AMD case appears broken. The callback in the wrapper which sets window.Strophe does not have Strophe defined. If I manually edit to look like this, I get further:

    _sendRestart: function ()
    {
        clearTimeout(this._conn._idleTimeout);
        this._conn._onIdle.bind(this._conn)();
    }
};

/* jshint ignore:start */
if (callback) {
    return callback(Strophe, $build, $msg, $iq, $pres);
}
return Strophe;
}));


})(function (Strophe, build, msg, iq, pres) {
    window.Strophe = Strophe;
    window.$build = build;
    window.$msg = msg;
    window.$iq = iq;
    window.$pres = pres;
});
/* jshint ignore:end */

Unfortunately, not much further. strophejs-plugins assumes that window.Strophe is defined before it loads, and of course it is not.

@jcbrand
Copy link
Contributor Author

jcbrand commented Apr 15, 2015

The non-AMD case worked fine for me when I tested it with converse.js's non_amd.html.

It's not clear from the code snippet above what you've actually changed.

@benlangfeld
Copy link
Contributor

I couldn't figure out the structure in the source files, but edited the concatenated source as so to bring Strophe into scope:

diff --git a/strophe.js b/strophe.js
index 9f13757..e76e5fe 100644
--- a/strophe.js
+++ b/strophe.js
@@ -5305,12 +5305,12 @@ Strophe.Websocket.prototype = {
     }
 };
 return Strophe;
-}));

 /* jshint ignore:start */
 if (callback) {
     return callback(Strophe, $build, $msg, $iq, $pres);
 }
+}));


 })(function (Strophe, build, msg, iq, pres) {

@benlangfeld
Copy link
Contributor

If you want to see how this breaks a non-AMD consumer of Strophe, check out candy-chat/candy#385.

@benlangfeld
Copy link
Contributor

Do you have any idea what might be wrong here or how I might hope to resolve this, @jcbrand?

@jcbrand
Copy link
Contributor Author

jcbrand commented Apr 15, 2015

@benlangfeld You say in that ticket that the app works and just the tests fail.

Perhaps the tests need to be changed? I don't know anything about the Candy tests or what assumptions they make.

Here's the non AMD version of converse.js, you can try it out for yourself to see that it works: https://conversejs.org/non_amd.html

In the developer console you'll see that Strophe is defined.

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

Successfully merging this pull request may close these issues.

3 participants