-
Notifications
You must be signed in to change notification settings - Fork 366
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
Conversation
All modules in src/ are now wrapped as AMD modules. Add main.js for usage with require.js. Add example/amd.html to show an example of Strophe.js working with require.js
Conflicts: Gruntfile.js Makefile src/core.js src/websocket.js
We need it to create strophe.js. The almond/r.js build cannot be used in its stead.
Add support for the Asynchronous Module Definition (AMD) and require.js
Use in a non-AMD case appears broken. The callback in the wrapper which sets _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 |
The non-AMD case worked fine for me when I tested it with converse.js's It's not clear from the code snippet above what you've actually changed. |
I couldn't figure out the structure in the source files, but edited the concatenated source as so to bring 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) { |
If you want to see how this breaks a non-AMD consumer of Strophe, check out candy-chat/candy#385. |
Do you have any idea what might be wrong here or how I might hope to resolve this, @jcbrand? |
@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. |
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