Meteor "use strict" with global alias - meteor

In another SO post here, the second option is to write G.this; in the first "top" file in order to create a namespace.
And then write "use strict" on the top of every other js file.
Is that all the content of such a file? and if so, where the "top" file should be located (server, client, both) and what name? as Meteor loads files based on their paths. Thanks

One of ways to create a global namespace in Meteor (as suggested in the SO answer) is to have a file where a global alias to this is declared, such as:
G = this;
This file should, ideally, be loaded first and on both client and server.
To achieve this, according to the doc:
Files within lib/ directory are loaded first (after loading template files on client).
Meteor will load any file outside client/ or server/ directories on both client and server.
Where no other rules may apply, alphabetical ordering of the paths is used to determine load order of the files.
So, in keeping with these rules I would save the file as app.js (or any similar name that would come first alphabetically). Then I would place this file at the root of lib/ folder so that it gets loaded both on client and server.
So, the path to app.js would be : ./your_meteor_project_root/lib/app.js

Related

Is there a way to serve a directory using map local and Charles?

I have a network request in the form of:
http://www.blahblah.com/folder/version/dist
I would like to add a rule to the Map Local option in Charles, in order to serve a directory that looks like:
Users/me/Documents/code/project/dist
The file structure of both dist folders are the same. My current request rule is: http://www.blahblah.com/folder/*/dist, and I'm asking it to serve Users/me/Documents/code/project/dist in its place, however, the files still come from the original requested resource.
Is there a way to proxy a whole directory?
You should be able to do so, by what is said in the CharlesProxy documentation:
If you are testing css, swf or image changes you can map those file types to your local development copy of the website so you can browse the live site with all your development assets. Create a mapping from live.com/*.css to the root of your local development copy, and similar mappings for the other file types. Alternatively you can map whole directories or individual files as required.
I guess your problem might be on the path where you are trying to map from. I would say you need to add an asterisk at the end of your path, something like:
http://www.blahblah.com/folder/*/dist/*
You can try to add the .css as done in the example
http://www.blahblah.com/folder/*/dist/*.css

Calling Meteor server side methods from public js asset

What is the approach for doing a Meteor.call to the server from a js file within the /public folder?
I tested, but the call does not work. I am unable to get any result from Meteor.call when using it within the js filed that is served on the public...
Will I need to create a middleware api ?
Why is the JS file in the public directory? If you want the JS code to be executed on the client, then put it in the /client directory and the functions will be available to the client.
If it's in the public folder, then it is served "as-is" to the client. From the docs:
public
All files inside a top-level directory called public/ are served as-is to the client. When referencing these assets, do not include public/ in the URL, write the URL as if they were all in the top level. For example, reference public/bg.png as . This is the best place for favicon.ico, robots.txt, and similar files
UPDATE
Since now I can see you are trying to load an external JS, the correct answer is to either use NPM (with meteor 1.3+) or place them in the client/compatibility directory. From the docs (http://guide.meteor.com/structure.html):
client/compatibility
This folder is for compatibility with JavaScript libraries that rely on variables declared with var at the top level being exported as globals. Files in this directory are executed without being wrapped in a new variable scope. These files are executed before other client-side JavaScript files.
It is recommended to use npm for 3rd party JavaScript libraries and use import to control when files are loaded.

Issues with files naming when useing filerev & usemin

Lets assume I have 2 static assets (html files) in my project, files a.html and b.html.
File a.html has a link to file b.html inside of it.
Now I run a build and the 2 files got their name changed and everything is working fine (by the filerev module).
Now I need to make a small change only in file b.html -> filerev will give a new name to file b.html in the next build. Because file a was not changed it will have the same name as the prev build.
Now, in the next build usemin will go to file a and will fix the link to the new file b name and everything looks fine. But not, because file a still has the same name as prev build, users will get a broken link when trying to access file b from a.
I guess a workaround is to instead of having hashes of the file names, generate random file names each time.
That way you are generating all files so it is not optimized, but you prevent the caching problems between versions, while still allow caching of the browser for the same version.
Using the grunt-angular-template task can solve this issue as it is adding all the templates to the $templateCache of angular, so the no real requests will be made to the server when a template is requested and the recent template is loaded from the cache. Of course it is not ideal as in big applications you will not want this as this may increase your js file size

Xcode static library appears twice

I added the OCMock static library in Xcode with some header files.
I'm not sure what's changed since I added it but the file now appears twice in the Project Navigator - once at the top level and once under the usr/lib folders.
How do I get rid of the second (highlighted) listing?
It looks like you added OCMock's whole "usr" folder via a folder reference, most likely by accident.
You have three choices for a solution:
1)
Remove the "usr" folder from your list of files & folders in your project, and re-add just the "include" folder via folder reference (I'm presuming you want to use the folder reference so you can pick up the latest header files that are in there?).
2)
Add the required header files to your project directly (i.e. not using the folder reference).
3)
Or get rid of the first "libOCMock.a" library and just rely on the folder reference to pick up the static library living under the "usr" hierarchy.

Ordering of the css and js files loaded by Meteor

Is there any way of specifying an order to the automatically loaded css or js files loaded by Meteor.
Searched the docs and can't find anything.
I ask because I'm at the playing about stage, and am trying to use Twitter Bootstrap with Meteor. In the examples that come with Bootstrap the base bootstrap.css is always loaded before the bootstrap-responsive.css.
Any ideas?
This question has since been answered in http://docs.meteor.com/
The JavaScript and CSS files in an application are loaded according to
these rules:
Files in the lib directory at the root of your application are loaded
first.
Files that match main.* are loaded after everything else.
Files in subdirectories are loaded before files in parent directories,
so that files in the deepest subdirectory are loaded first (after
lib), and files in the root directory are loaded last (other than
main.*).
Within a directory, files are loaded in alphabetical order by
filename.
These rules stack, so that within lib, for example, files are still
loaded in alphabetical order; and if there are multiple files named
main.js, the ones in subdirectories are loaded earlier.
You are correct, user files are loaded depth first, alphabetically otherwise.
https://guide.meteor.com/structure.html#load-order
lib/ directories and main.* files are special cases.
Packages can also alter load order, but I don't think any of the default packages do that.
Running on windows, the other solutions didn't work for me so I just put all the js files into 1 folder and just number them. Meteor loads them in alphabetical order.

Resources