www.rozumim.cz

What I've learned ~ 1

JavaScript (ES2015)

Turn an iterator into an array

For example the method Map.keys() returns an iterator. You can use the spread operator to get those keys as an array like this:

1
[...myMap.keys()]  

React

Playing with React in JSBin

JSBin is super useful for quick testing. Take a look at the article React, JSX, and ES6 example “Hello World” with JSBin in 4 minutes.

JSBin warning: use esnext option

This warning comes from JSHint that JSBin uses internally. You can tell JSHit to allow constructs from ES2015 using this comment in your code:

1
/* jshint esnext: true */ 

Quiz

What will render the following component? Can you spot the error?

1
2
3
4
5
6
7
8
class Hi {
  render() {
    return
     <div style={{ background: 'red'}}>
       <h1>Hi</h1>
     </div>;
  }
}

You can experiment with it here.

The corrected version, that renders what you’ve probably expected, is here:

1
2
3
4
5
6
7
8
9
class Hi {
  render() {
    return (
     <div style={{ background: 'red'}}>
       <h1>Hi</h1>
     </div>
    );
  }
}

(and here).

Atom

Alt-f in Atom is bind to move forward one word

This unfortunate default behavior is easy to fix. Go to Packages > Settings View > Show Keybindings > click on the link into your keymap file and add the following:

1
2
 'atom-text-editor':
    'alt-f': 'native!' 

Source: Windows: Allow Alt-key bindings to override menus. #474

4. 10. 2015, kategorie:
comments powered by Disqus