-
Notifications
You must be signed in to change notification settings - Fork 493
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
vex.close() undefined under CommonJS/Browserify #72
Comments
ill check this out |
Thanks @ngault and @hugomrdias |
can you post a snippet of your code here pls ? |
hugomrdias, here's a gist with the CommonJS wrapped version of Adam's login example, packaged, as it must be, with its dependencies. At the bottom of this (sorry) long post, I provide a version of stripped of wrapper and dependencies. DevTools showing the example code choking on vex.close(): A quick recap of my take on the problem because I may have been unclear in my original description: Consistent with the notes to your PR, to Instead, as you do in your PR, we must assign the module like this: ...and, as we know, there is no such function in vex as: End of recap. Here's the code (exactly the same as Adam's, except for the
|
i didn't setup a local demo with your gist but i think i got the problem.
'use strict';
var vex = require('vex'),
VexDialog = require('vex/js/vex.dialog.js');
VexDialog.prompt({
appendLocation: '.header-interior-leftmost-pad',
className: 'vex-theme-wireframe',
message: 'Use "test@test.com" with password "test" ',
input: '<input name="email" type="email" class="vex-dialog-prompt-input" placeholder="email@example.com" value="" required>\n<input name="password" type="password" class="vex-dialog-prompt-input" placeholder="password" value="" required>',
onSubmit: function(event) {
var $vexContent;
event.preventDefault();
event.stopPropagation();
$vexContent = $(this).parent();
return login(this.email.value, this.password.value, function(message) {
if (message === 'success') {
// now vex should be available
return vex.close($vexContent.data().vex.id);
} else {
return console.error(message);
}
});
}
}); vex.dialog doesn't work like a jquery plugin it doesn't attach it self to the main vex object instead it requires vex instance and calls it with specific options for .alert, .confirm etc etc. vex is a singleton holding all the active dialogs, vex.dialog is just static methods calling vex with different options. Please follow these instructions and report back, hopefully im right if not ill have a second look a it. @adamschwartz what you think about registering with npm and maybe adding some docs for commonjs enviroments |
Thanks for pushing on this. @hugomrdias As I don’t use CommonJS this stuff is a little unfamiliar to me. That being said I’m happy to merge any PR’s to the docs which help people understand what’s going on. Currently the docs contain this message: Does that not fully explain the situation? Again, sorry if I’m missing something here. @timmfin also wondering if you have any thoughts here. |
@adamschwartz , thanks for pointing out that the docs instruct CommonJS users of vex.dialog.js to NOT also require vex.js. You are not missing anything, this is precisely the issue. PR 71 and the docs are not compatible. I believe that the current documentation describes the way that a CommonJS/npm of vex.dialog.js SHOULD work: the use of a single module should not demand explicit statement of its dependencies. (In that sense, CommonJS is unlike AMD.) That's what npm users expect. So, if you want a fix that follows CommonJS/npm convention, I'd leave the documentation as is and decide upon the best way to make available vex.close(). @hugomrdias, granting the accuracy of your explanation about how multiple vex.dialog objects attach themselves to the single vex object, I'd argue that this is an implementation detail that a user of the library shouldn't be expected to know. I'd argue that a more important consideration to the design of your solution is the comprehensibility of the API. |
@ngault i reviewed the code again and what i said earlier isnt 100% accurate, vex and vex.dialog are just objects with static methods they always check the DOM for the dialogs, etc.. its up to @adamschwartz because i dont do coffee script :) sorry personally i'm happy for now it works with cjs/browserify even if we need to require both files. |
Hugo, thanks for looking into this and getting back to me so fast. I agree, the most important thing is that with your PR we can now use vex.dialog.js under CommonJS/npm/browserify. Adam will just need to change the docs, otherwise anybody using the new vex.dialog.js will get stuck. |
…on because vex' commonjs support is broken. HubSpot/vex#72
Hey all! See my comment on #60 and let me know if your issue is resolved! Thanks! |
Assuming this is ok now, we've had standalone module support for a while. |
I’m creating a new issue about this because I notice that adamschwartz just merged hugomrdias’ PR 71, making NPM distribution a possibility…which is great. Thank you!
But… it doesn’t appear that folks realize that using
vex.dialog.js
with CommonJS/Browserify won’t work in the case of (by my count) about 60% of all Vex examples posted by Adam over date because of CommonJS namespacing.In particular, if you
require
under CommonJSvex.dialog.js,
the key methodvex.close()
isundefined
. (There is no such thing asvex.dialog.close(),
of course.) To reproduce the problem, try Browserify'ing some of Adam's JSFiddle examples, such as:http://jsfiddle.net/adamschwartz/Lrq84/
or
http://jsfiddle.net/adamschwartz/r27K5/show/light/
which is described in depth here
#59
Vex currently offers:
As a solution to this namespacing problem, my personal taste would NOT be to make
vex.close()
available to thevex.dialog
object, but rather to create a new method namedvex.dialog.close()
. But I'll be happy for any fix that will allow me to Browserify my existing Vex dialogs, which are dependent onvex.close()
The text was updated successfully, but these errors were encountered: