-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Store is undefined when loading into a page that already uses AMD #96
Comments
Yeah, this shit is a clusterfuck. Do you have a proposed solution? |
How are you loading store.js? Are you a library provider? Perhaps check if amd is being used ( Are you from Sweden by any chance? I am originally, but lived in Chicago for 4 years. Freakin' cold!! |
At the moment, we are using a custom version (removed the Node and AMD checks). I'd like to see a fixed version so we don't have to hack up the code every time we want to upgrade. I'm not real familiar with require.js. Surely, this problem is a common one, right? |
I'm not from Sweden, but my great-grandfather was. He settled in ND (which is where I was born). I've been in Chicago almost 25 years. |
Sorry, ND = North Dakota. |
I'm not sure how common the problem is - not many people report having this I'm ears all open for a proper solution. I ask every time someone brings up On Tue, May 27, 2014 at 5:54 PM, Kevin Gustavson
|
I guess you could call us third-party. At least in the sense that the page is already established and the require.js stuff is handled by someone else. The reason that I thought this would be common was because there should be lots of pages where additional amd-aware libraries are loaded into a require.js managed site. |
Do you have an example of a library that does it right in all cases? I'm On Tue, May 27, 2014 at 6:01 PM, Kevin Gustavson
|
Unfortunately, no. As I said, I’m not very familiar with require.js. I may end up facing a similar issue in the near future. I have a jQuery plugin that should be made AMD compatible. |
@kgust I think ideally you should wrap every module brought in by your component carefully to make it "self-contained" and "no global pollution", so it doesn't affect the other's require.js context or conflict with existing global name spacing. for doing that, you can use something like this https://github.com/normanzb/amdshim to build your project. Simply say, it is lightweight version of AMD APIs that provide an internal implementation of require() and define(), so that while benefiting from using require js, your component will stay self-contained and green. Alternatively, if you don't mind polluting the other's web page, you can always define store as a global object at https://github.com/marcuswestin/store.js/blob/master/store.js#L165, but i strongly against this approach as it may still conflict with target page, what if the webpage is using store.js and they are using a different version? |
I can't verify currently with the problematic site, but this should fix it. |
Thanks Kevin On Wed, Mar 11, 2015 at 2:17 PM, Kevin Gustavson [email protected]
|
We tried loading store.js into a site that had require.js (which was outside our control and loaded modules unrelated to what we were doing).
We use window.store to access store. In this case,
define.amd
was defined so the code tries to calldefine(store)
instead.Because
window.store
is not defined, our code doesn't run.NOTE: This is related to Issue #91 but is a different problem.
The text was updated successfully, but these errors were encountered: