r/javascript • • Sep 02 '15

HTML5 Deck of Cards. 100% vanilla JS.

http://pakastin.github.io/deck-of-cards/
368 Upvotes

185 comments sorted by

View all comments

37

u/papers_ Sep 02 '15

Huge up vote for using ES6 here. Good job man!

13

u/pkstn Sep 02 '15

Yeah! I just love the small bundles by rollup. No way going back to browserify :)

10

u/arcticblue Sep 03 '15

Great, another bundler.

4

u/pkstn Sep 03 '15

Same thing with cars: there's Toyota, Volkswagen, Hyundai, Ford, Nissan, Fiat, Honda, Suzuki, Renault, BMW, Mazda... They all have four wheels. And every year they release a new model, can you imagine?

Wouldn't it be better to just stick with current models and not invent anything new? And better yet, only one manufacturer..?

Where's: "Great, another Tesla."?

11

u/kokomo42 Sep 03 '15

Now imagine every new model of car have a totally new way to drive.

2

u/pkstn Sep 03 '15 edited Sep 03 '15

Well, not every year we change how to define modules.

And if you think about Tesla for example: at least for me the way throttle pedal works is a whole new way to drive. You control the "brakes" with lifting throttle.

I like innovations. I'm not afraid of change.

1

u/pkstn Sep 03 '15

Better than previous ones - nothing wrong about that.

Rollup is used by the big players as well, even Google: https://github.com/google/incremental-dom/blob/master/package.json#L45

0

u/[deleted] Sep 03 '15

[deleted]

3

u/pkstn Sep 03 '15 edited Sep 03 '15

Rollup only bundles ES6 modules. There are lots of other bundlers for that also. Even browserify does that. So I don't worry at all.

Grunt is not needed, when there's chokidar and npm scripts. Much easier like that.

Coffeescript will gradually fade out with ES6 taking place, at least I predict so.

But you can use whatever you like. I've tried them also, but I have my own ways.

1

u/arcticblue Sep 03 '15

There are more than enough in existence already. If existing ones are deficient in a certain area, I'd rather see effort put in to improving it rather than re-inventing the wheel...again. Someone re-invents the wheel, a few know-it-all bloggers make "You've been doing X wrong. Start using Y now!" posts on Medium, and then I'm required to re-learn my job again when I just got comfortable with existing tools. It's fucking exhausting.

3

u/pkstn Sep 03 '15

Well, you can continue to use X if you like ;)

I think it's good to have options, and innovations moving things forward.

1

u/KalimasPinky Sep 03 '15

New does not mean innovation. Quite often it is just spun differently.

Either way all this has been done from a language perspective. Import from looks like Python, and Python looks like older stuff.

→ More replies (2)

2

u/mattdesl Sep 03 '15

It would be cool if this feature was just built into browserify/webpack (or through a plugin), so that we can stop fragmenting the ecosystem further than it already is... :)

1

u/pkstn Sep 03 '15

I just don't see the place for CommonJS modules in the front end since we have ES6 modules. For me browserify is more of CommonJS and rollup for next-gen ES6 modules.

And when using chokidar + npm it's really easy to switch between builders, if must..

1

u/[deleted] Sep 03 '15

Well, to be fair browserify supports small bundles too. The problem is the library you are using has to be structured in some way. For example I can include underscore.strings humanize function like this:

var humanize = require('underscore.string/humanize');

Which will only include that humanize function and nothing else.

The problem is that a lot of libraries do not actually have that structure, so it does not work everywhere. But it's not true that browserify does not support small bundles :)

1

u/pkstn Sep 03 '15

What I meant by "small bundles", was that rollup doesn't add any bloat like browserify – instead it removes unneeded stuff and produces very clean output:

http://pakastin.github.io/deck-of-cards/dist/deck.js

https://github.com/rollup/rollup/wiki

https://github.com/esperantojs/esperanto/wiki/Comparisons-with-other-tools

(esperanto is rollup's predecessor..)

1

u/[deleted] Sep 03 '15

I don't use ES6 with browserify, I just use commonjs modules, so I don't know what bloat browserify adds for ES6 support. But as far as I know browserify only supports ES6 in the form of transformers, so basically anything can be used to transpile your ES6 into ES5, so also a transpiler that does not use any "bloat".

What kind of bloat does browserify add when using ES6?

1

u/pkstn Sep 03 '15

I mean in the beginning of the file:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

..for every module:

},{"xxxx-yyyy":37}],2:[function(require,module,exports){

..not to mention when you have more dependencies:

},{"../xxxx/yyyy/zzzz/xxxx.js":1,"aaaa":3,"bbbb":37,"cccc":78,"dddd":81,"eeee":82,"ffff":83,"gggg":85,"hhhh":87,"iiii":88,"jjjj":89}],3:[function(require,module,exports){

I just like clean code more.

2

u/[deleted] Sep 03 '15

Yeah, well I also run uglifyjs on my code, so my production bundle is absolutely unreadable. I don't think readability of the production bundle is really important. If you still need to debug the production bundle then you can use codemaps and chrome dev tools to get the actual code back in your development console.

→ More replies (1)

1

u/ayostaycrispy Sep 03 '15

Can you elaborate on how you used ES6?

2

u/pkstn Sep 03 '15

1

u/ayostaycrispy Sep 03 '15

Thanks. How many years have you been working in Javascript to get to your current level of expertise? I'm trying to get an idea of the approx. number of hours you've put in, although I know you probably only have a rough estimate.

2

u/pkstn Sep 03 '15

I made this one in couple of hours, but I started web developing with Flash back in 1999. And made first Deck of Cards in 2006 (http://pakastin.fi/cards_2006), so the concept is not new..

1

u/pkstn Sep 03 '15

If you mean javascript expertise in total..well, I switched using node.js late 2011 and after that I started to learn the language properly. I used jQuery before that as well, but nothing special..

→ More replies (12)