Discuss Scratch

liam48D
Scratcher
1000+ posts

ES6?

Some things I'd like to suggest involving ES6. I'm just wondering if it's okay if we use these things in the various projects?

ES6 supports destructuring:
// old:
var injectIntl = require('reactl-intl').injectIntl;
// new:
var { injectIntl } = require('reactl-intl');
Requires the extra –harmony_destructuring flag though.

Function methods of objects are a lot nicer now:
// old:
var View = injectIntl(React.createClass({
    ...
    getInitialState: function() {
        ...
    }
    ...
});
// new:
var View = injectIntl(React.createClass({
    ...
    getInitialState() { // no more "function"
        ...
    }
    ...
});

Last edited by liam48D (Feb. 2, 2016 16:39:00)


202e-202e-202e-202e-202e UNI-CODE~~~~~
kvackkvack
Scratcher
500+ posts

ES6?

You really do love ES6, don't you? :P
Anyway, I don't see why this wouldn't be okay. If you want to make a change to the site and can't resist using ES6, you can just use Babel (that's what it's called, right?) or something to compile it to normal, usable-for-ST code.
GrannyCookies
Scratcher
100+ posts

ES6?

kvackkvack wrote:

you can just use Babel
Problem is that Babel creates near-unreadable code.

liam48D
Scratcher
1000+ posts

ES6?

GrannyCookies wrote:

kvackkvack wrote:

you can just use Babel
Problem is that Babel creates near-unreadable code.
^^^

202e-202e-202e-202e-202e UNI-CODE~~~~~
thisandagain
Forum Moderator
500+ posts

ES6?

liam48D wrote:

Some things I'd like to suggest involving ES6. I'm just wondering if it's okay if we use these things in the various projects?

ES6 supports destructuring:
// old:
var injectIntl = require('reactl-intl').injectIntl;
// new:
var { injectIntl } = require('reactl-intl');
Requires the extra –harmony_destructuring flag though.

Function methods of objects are a lot nicer now:
// old:
var View = injectIntl(React.createClass({
    ...
    getInitialState: function() {
        ...
    }
    ...
});
// new:
var View = injectIntl(React.createClass({
    ...
    getInitialState() { // no more "function"
        ...
    }
    ...
});
We are starting to use ES6 modules in a few new projects and that style will likely make it back to the scratch-www repo in the near future. For now, we'd prefer that you stick with the coding convention we have established. Using ES6 modules with Babel requires some changes to our build process and thus would require quite a bit of additional testing and QA.
liam48D
Scratcher
1000+ posts

ES6?

thisandagain wrote:

liam48D wrote:

Some things I'd like to suggest involving ES6. I'm just wondering if it's okay if we use these things in the various projects?

snip
We are starting to use ES6 modules in a few new projects and that style will likely make it back to the scratch-www repo in the near future. For now, we'd prefer that you stick with the coding convention we have established. Using ES6 modules with Babel requires some changes to our build process and thus would require quite a bit of additional testing and QA.
Okay, sounds good.

202e-202e-202e-202e-202e UNI-CODE~~~~~
liam48D
Scratcher
1000+ posts

ES6?

*scowls at somebody who's post got deleted*

EDIT: Oh looks like they got deleted. Yay moderators!

Last edited by liam48D (Feb. 9, 2016 15:46:36)


202e-202e-202e-202e-202e UNI-CODE~~~~~
MegaApuTurkUltra
Scratcher
1000+ posts

ES6?

liam48D wrote:

*scowls at somebody whose post got deleted*

EDIT: Oh looks like they got deleted. Yay moderators!

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
liam48D
Scratcher
1000+ posts

ES6?

MegaApuTurkUltra wrote:

liam48D wrote:

*scowls at somebody whose post got deleted*

EDIT: Oh looks like they got deleted. Yay moderators!
oh yes that makes sense, “who's” is “who has”. sorry i sometimes can't english.

202e-202e-202e-202e-202e UNI-CODE~~~~~
Jonathan50
Scratcher
1000+ posts

ES6?

liam48D wrote:

ES6 supports destructuring:
// old:
var injectIntl = require('reactl-intl').injectIntl;
// new:
var { injectIntl } = require('reactl-intl');
Requires the extra –harmony_destructuring flag though.
Ooh, ML/Haskell style pattern matching. Can you do it in procedure definitions…?
function foo(a, [b, c]) {
  console.log(b);
  console.log(c);
}
 
function bar({a, b}) {
  console.log(a);
  console.log(b);
}
 
foo(42, [1, 2]);
bar({a: "foo", b: "bar"});
YES! IT WORKS! I LOVE IT!

This makes everything more amazing.
But the one other thing ECMAScript is really really lacking is requiring tail call optimization.

EDIT: you can't match against literals and it's not exactly pattern matching, but whatever

Last edited by Jonathan50 (May 1, 2016 04:26:04)


Not yet a Knight of the Mu Calculus.
Jonathan50
Scratcher
1000+ posts

ES6?

GrannyCookies wrote:

kvackkvack wrote:

you can just use Babel
Problem is that Babel creates near-unreadable code.
But… Babel's output is compiled. It doesn't really matter what it looks like because you should be editing the source.

Not yet a Knight of the Mu Calculus.

Powered by DjangoBB