DiscoverMeteor / book

17 stars 0 forks source link

Making a normal website in meteor #417

Closed cfry closed 9 years ago

cfry commented 9 years ago

http://www.smashingmagazine.com/2013/06/13/build-app-45-minutes-meteor/ by one of the book authors shows us something not in the book, as far as I can see, ie making a meteor website that has an A tag with a link to a remote web page that opens in a new window in a browser. But what if we want to open a new window/tab to a page that is in our meteor app? I had hoped is that Help with a file in my meteor app's public directory named "help.html" that looks like a normal web page, ie stuff But when I click on the link, I get a new tab in my chrome browser with the url http://localhost:3000/help.html (I guess that's ok,) but the page is empty. Others have had trouble with this, see: http://stackoverflow.com/questions/13910184/how-to-make-link-open-in-new-tab-or-window-in-meteor

On http://docs.meteor.com/#/basic/, The very first sentence, in bold and a header is: "Meteor is an ultra-simple environment for building modern websites. " The most basic feature of a website is the A tag. I suggest your book start with making a 2 (static) page website where you click on a link in one web page and see the other. (and tell us how to put that in a new tab if its as tricky as it seems) If you need templates, or Javascript or Iron or reactive anything to do this, then state at the top of this "chapter 0" that the above statement from http://docs.meteor.com/#/basic/ is false so us poor users out here will have some confirmation of reality.

PS: I'm using windows 7, meteor 1.1, Chrome 41, Webstorm 10 cfry42@gmail.com Thanks for trying!

SachaG commented 9 years ago

I'm not sure I follow, but you can't just create a help.html file and have it show up at /help.html, that's just not how Meteor works.

If you'd like something that works like this you could look into PHP?

cfry commented 9 years ago

Thanks for your speedy response. I build very complex dynamic apps on the web. But that doesn't mean that I don't ALSO need some of the "easy" stuff that normal tools like PHP provide in these complex apps.

My goal here is to help you make the DiscoverMeteor book as good as possible. I bought it and consider it a good source of information, probably I'll refer back to it for years.

The article that I referenced that you wrote had some quite useful content about using Meteor for this "easy" stuff that, as far as I can tell, isn't in the book. In particular, it showed how to make an A tag that opened a new browser tab to a web page that was on a different site than the Meteor site that hosted the page that had the A tag on it. What seemed strange to me was that it can't ALSO link to a page on the same (meteor) website. This is like making a PLUS function that only works on negative numbers.

I infer from your message that the quote from the Meteor website: "Meteor is an ultra-simple environment for building modern websites. What once took weeks, even with the best tools, now takes hours with Meteor."

Is false, at least for the most normal kind of website, one with pages that link to one another. Now Meteor provides a ton of sophisticated technology and can't be expected to do everything, but if it can't do this simple thing simply, that's just poor design period. You telling me "that's just not how Meteor works" may well be accurate. But it begs the question "how does it work?" Saying "go use PHP" is telling me that Meteor doesn't work for this extremely normal case. Well, let's do something about that! (note: I am not so concerned that I can't use exactly the same syntax in Meteor for this case as in normal web programming. I am concerned that it isn't documented and that its apparently not easy.)

Readers who come to DiscoverMeteor will be expecting that Meteor can do the easy stuff easily. Telling them that it can't will at least stop them from wasting time because this is one of those things that "you're sure it must be here somewhere" and you keep looking. Regardless of how easy or hard it is to do this "easy stuff", I think a great addition to Discover Meteor would be telling readers how do to this very common functionality in Meteor as simply as possible. That would help many of us.

I also bet that the folks that develop meteor could extend meteor to make this common use case easy. I've done a lot of programming language design. Sometimes you focus so hard on the difficult, sophisticated functionality that you forget the more mundane, utilitarian functionality. If you have any contacts there, and would like to forword this email, that's fine by me.

From: Sacha Greif [notifications@github.com] Sent: Thursday, April 02, 2015 5:17 AM To: DiscoverMeteor/book Cc: cfry Subject: Re: [book] Making a normal website in meteor (#417)

I'm not sure I follow, but you can't just create a help.html file and have it show up at /help.html, that's just not how Meteor works. If you'd like something that works like this you could look into PHP? � Reply to this email directly or view it on GitHub.

SachaG commented 9 years ago

Well, regarding the <a> thing in my experience anchor tags behave just like anywhere else, and target="_blank" works as usual (just tested it right now on http://meteorpad.com). Maybe that SO thread is outdated?

SachaG commented 9 years ago

If you need templates, or Javascript or Iron or reactive anything to do this,

Also Meteor is a JavaScript framework, so I'm afraid that yes, you do need JavaScript to do anything with it. It's a bit like how a car needs gas to go anywhere, even if it's only a couple meters :)

cfry commented 9 years ago

Let me state some of my assumptions:

Next on your comments below, if JavaScript was all you needed to know to code a Meteor app, then I'd agree that you'd need to know how to get the A tag functionality in JavaScript. But your article about A tags didn't mention this and you need to know HTML to use Meteor.

As far as your car analogy, in a normal web page, even one with Javascript on it, you don't have to know JavaScript to use the most basic, reason-for-existence of the web, the A tag. You use something like: Help

A few posts ago I indicated that the above should just work in Meteor and you responded: " ...you can't just create a help.html file and have it show up at /help.html, that's just not how Meteor works. If you'd like something that works like this you could look into PHP? "

I moaned about bad language design and how programmers who need the power of Meteor also need the power of HTML.

Tonight I got back to trying to solve this issue. I found some stack overflow discussion about how to do this with Meteor's templates plus some js, and was all set to try it. But decided to check my naïve implementation just to see what error message I'd get, as I forgot what that was the last time I did it. Guess what? It worked. Since I hadn't downloaded a new version of Meteor, and just checked that it was still the 1.1.6 of March 31, I was stunned. (my dot html file is in the public directory.)

OK now your knowledge of Meteor is a superset of mine!

In the mean time, I wrote down a bunch of problems I had with Meteor. I think there needs to be a chapter about "Converting a vanilla web app to Meteor" which is what I've been doing. But actually, we don't really need more documentation. Better is that the meteor software itself, and the meteor.com website should just be fixed to make such a chapter unnecessary. Just like, somehow, the above A tag stuff got fixed and those posts on stackoverflow are now unnecessary. http://stackoverflow.com/questions/13910184/how-to-make-link-open-in-new-tab-or-window-in-meteor

Anyway, perhaps you'll find the attachment useful. Thanks for being patient with me. Fry

From: Sacha Greif [notifications@github.com] Sent: Thursday, April 02, 2015 8:07 PM To: DiscoverMeteor/book Cc: cfry Subject: Re: [book] Making a normal website in meteor (#417)

If you need templates, or Javascript or Iron or reactive anything to do this, Also Meteor is a JavaScript framework, so I'm afraid that yes, you do need JavaScript to do anything with it. It's a bit like how a car needs gas to go anywhere, even if it's only a couple meters :) — Reply to this email directly or view it on GitHub. Meteor for Web Programmers Fry, April 5, 2015

If you don't know HTML and Javascript, then this article is not for you, and neither is Meteor. If you do, and you're reading this, you've probably heard how great Meteor is and willing to give it a try. You're willing to give it a try because the web circa 2015 is an unmitigated disaster for programmers. You have to know many languages, and how they interact. Meteor promises that you only have to know one, and you already know it, Javascript. So the attraction to Meteor is pretty strong.

Meteor might well be the best web programming system in 2015. Unfortunately it is marred by mis-information that will unnecessarily confuse you. It will slow you down, perhaps to the point of giving up on Meteor.

You can go to meteor.com and other sources to learn the wonderful things about Meteor. This article is the unwonderful stuff that you'll either

What You have to Unlearn in using Meteor. First is the Meteor hype. From: https://www.meteor.com/ "Meteor is a complete open source platform for building web and mobile apps in pure JavaScript."

and on "http://docs.meteor.com/#/basic/sevenprinciples" under their "Principles of Meteor" "One Language. Meteor lets you write both the client and the server parts of your application in JavaScript." This is contracticted by the above Meteor url on the same page. scroll down until you see the sample code of a Meteor app:

My website!

Doesn't look like Javascript to me.

To untangle this bs, understand that the phrase "pure javascript" is ambiguous. It could mean:

  1. All of your app is written in Javascript.
  2. When you do use Javascript, its "pure".

1 is false because there are many languages you need to know to code a Meteor app.

First understand that a language is a mapping between syntax and semantics. To the extent that this mapping is not 1 to 1, you don't have one langauge. So what languages do you need to know? At least: 1 meteor_HTML 2 meteor_javascript 3 ejson 4 css3 5 Jquery 6 url 7 spacebars (templating language) 8 meteor command line language

I'm not a math genius, but using meteor_javascript, 8 == 1 returns false.

Meteor includes "underscore", but since that's a pretty straightforward Javascript library, I don't count that as another language. Though Jquery is a Javascript library, it is anything but straightforward.

2 is false because there are certain things in Javascript that you can't use in Meteor.

See below.

HTML: Meteor uses a varient of HTML that I call meteor_HTML becauses the meteor developers deny that it exists.

meteor_html omits the tag HTML from regular HTML. Workaround: delete the wrapper from your main HTML file.

meteor_html considers all html files to be one big file and concatenates them all together to make one file to display workaround: difficult. YOu can wrap around your non-main html file then figure out how to display these templates.

meteor_html use to screw up A tags, esp those that point to a file that you want to be in your meteor website. But as of Meteor 1.1.6, this seems to be working. How to: Put your foo.html file in a directory named "public" which is at top level in your project. Put a slash as the first char of the value of 'href'. Example: Open foo in a new tab

Javascript: Meteor uses a varient of Javscript that I call meteor_javascript becauses the meteor developers deny that it exists. meteor_javascript defiencies from regular Javascript:

function foo(){} in regular js defines a global function that you can reference from another file. meteor_javascript uses this construct to define a function that is only accessible from the file that its in. Workaround: foo = function(){}


foo = [33, 44, 55] for (var x of foo){ } This is relatively new Ecmascript 6 JS defined in Chrome 40 and above and I think in Node.js 0.12 (current Mar 2015) but apparently meteor1.1 relies on node v 0.10 and looks like that doesn't support "for of" workaround: change your code to the primitive: foo = [33, 44, 55] for (var x_index in foo){ var x = foo[x_index]

}


alert is not defined on server side Meteor javascript. If you have a call to "alert" in server code, you'll get the confusing error of: "ReferenceError: alert is not defined" Confusing because the Meteor website claims it runs "pure Javascript".

workaround: if (Meteor.isServer) { console.log(text) } else { alert(text) }

What the Error message should say: "alert is not defined in server-side meteor_javascript. See "meteor.com/workarounds.html#alert"


Experienced Meteor programmers will poo-poo the above problems as minor. That's because they forgot how painful it was to debug these problems when learning Meteor.

Languages You DON'T have to Know when using Meteor

The above 2 are important advanages of Meteor.

Summary Web programming is one of the most difficult cognitive tasks humans commonly attempt in 2015. Designing "programming systems" to make this easier is of paramount importance. The clever folks at Meteor have some sophisticated tools for facilitating the making of complex web applications. They have made advancements in difficult jobs like "reactive" programming against a shared client and server side DB that are worth paying attention to. But its a huge problem space and they can't realistically be expected to get everything right for everyone (at least not by v 1.1).

If you want to put up a simple website, maybe even one with a little Javascript, don't use Meteor. That's like using a sldeghammer to swat a fly. But if you are looking for more, take a serious look at Meteor, though be mindful of their hype. They are a normal company in that regard; normal meaning their marketing is, to be generous, misleading. The goal of this article is to decrease your frustration and wasted debugging hours when attempting to transfer your web skills and code to a Meteor project. Proceed, but proceed with realism.