ecmascript-next

Error: Missing class properties transform

∥☆過路亽.° 提交于 2019-11-27 03:48:41
Error: Missing class properties transform Test.js : export class Test extends Component { constructor (props) { super(props) } static contextTypes = { router: React.PropTypes.object.isRequired } .babelrc : { "presets": ["es2015", "react", "stage-0"], "plugins": ["transform-class-properties"] } package.json : "babel-core": "^6.5.1", "babel-eslint": "^4.1.8", "babel-loader": "^6.2.2", "babel-plugin-react-transform": "^2.0.0", "babel-plugin-transform-class-properties": "^6.5.2", "babel-preset-es2015": "^6.5.0", "babel-preset-react": "^6.5.0", "babel-preset-stage-0": "^6.5.0", "babel-register": "

Unable to use Arrow functions inside react component class [duplicate]

梦想与她 提交于 2019-11-26 22:52:28
This question already has an answer here: How to use arrow functions (public class fields) as class methods? 4 answers I've started a project where i use React JS for the front end an node js in backend. I used webpack for bundling up JS files. i used babel along with other necessary stuff. When ever i use arrow functions inside a react class it gives a syntax error. like Module build failed: SyntaxError: Unexpected token . But i can use Arrow function in node without any issue. this is my webpack config file import path from 'path'; import webpack from 'webpack'; import 'react-hot-loader

Why await is not working for node request module?

白昼怎懂夜的黑 提交于 2019-11-26 19:56:55
问题 I'm new to nodejs. I’m not seeing the response in ex 1, but i see in ex 2. Why? Await works for me in other places, using babel. Ex 1 let res = await request(url) console.log(res); console.log(res.body); Ex 2 request(url, function (error, res, body) { if (!error && response.statusCode == 200) { console.log(body) } }); Await works in other places, I’m using babel and required modules for es6 and es7 features. For example, await works in squelize call, i validated. But it doesn’t work for

Is it better to define state in constructor or using property initializers?

会有一股神秘感。 提交于 2019-11-26 18:43:13
According to this babel documentation, the correct way to use ES6+ with React is to initial components like this: class Video extends React.Component { static defaultProps = { autoPlay: false, maxLoops: 10, } static propTypes = { autoPlay: React.PropTypes.bool.isRequired, maxLoops: React.PropTypes.number.isRequired, posterFrameSrc: React.PropTypes.string.isRequired, videoSrc: React.PropTypes.string.isRequired, } state = { loopsRemaining: this.props.maxLoops, } } But some official examples, like Dan Abramov's own React DnD module, uses ES6+ but still defines state within the constructor:

How to know if a function is async?

自作多情 提交于 2019-11-26 18:04:10
问题 I have to pass a function to another function, and execute it as a callback. The problem is that sometimes this function is async, like: async function() { // Some async actions } So I want to execute await callback() or callback() depending on the type of function that it is receiving. Is there a way to know the type of the function?? 回答1: Native async functions may be identifiable when being converted to strings: asyncFn[Symbol.toStringTag] === 'AsyncFunction' Or by AsyncFunction

What does the at symbol (@) do in ES6 javascript? (ECMAScript 2015)

老子叫甜甜 提交于 2019-11-26 17:41:14
I'm looking at some ES6 code and I don't understand what the @ symbol does when it is placed in front of a variable. The closest thing I could find has something to do with private fields? Code I was looking at from the redux library : import React, { Component } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'redux/react'; import Counter from '../components/Counter'; import * as CounterActions from '../actions/CounterActions'; @connect(state => ({ counter: state.counter })) export default class CounterApp extends Component { render() { const { counter,

How to filter Object using Array.prototype.filter?

怎甘沉沦 提交于 2019-11-26 17:18:46
问题 Given var arr = [1,2,true,4,{"abc":123},6,7,{"def":456},9,[10]] we can filter number items within array arr using Number constructor var res = arr.filter(Number); // [1, 2, true, 4, 6, 7, 9, Array[1]] are true and [10] expected in resulting array ? If we substitute false for true at arr var arr = [1,2,false,4,{"abc":123},6,7,{"def":456},9,[10]] var res = arr.filter(Number) // [1, 2, 4, 6, 7, 9, Array[1]] using Array.isArray var res = arr.filter(Array.isArray) // [Array[1]] String var res =

JavaScript double colon (bind operator)

别等时光非礼了梦想. 提交于 2019-11-26 12:10:56
As you know, there is a proposal for a shortcut for .bind() function, so you can write: ::this.handleStuff and it will work like that in es5: this.handleStuff.bind(this) My question is: will it be possible to pass arguments this way? I mean a way of writing this with the aforementioned shortcut: this.handleStuff.bind(this, 'stuff') It's a pretty common pattern in React, so it would be nice to shorten it a little. Bergi No. The bind operator ( spec proposal ) comes in two flavours: Method extraction ::obj.method ≡ obj.method.bind(obj) "virtual method" calls obj::function ≡ function.bind(obj)

Using latest JavaScript features in TypeScript, such as ES2018

余生长醉 提交于 2019-11-26 11:11:29
问题 I have tried searching through TypeScripts documentation on their configurtion and can\'t seem to find the answer to what should be a simple question. Simply, how does one configure the typescript compiler so that it knows what JavaScript feature sets we are using? So for example, ES2019 lands and i think \'Ohh want to get me some of that\'. In that situation what do i need to upgrade, to allow the compiler to transpile and pollyfill what it needs to? The lib option in the tsconfig confuses

Correct use of arrow functions in React

那年仲夏 提交于 2019-11-26 09:25:02
问题 I am using ReactJS with Babel and Webpack and using ES6 as well as the proposed class fields for arrow functions. I understand that arrow functions make things more efficient by not recreating the functions each render similar to how binding in the constructor works. However, I am not 100% sure if I am using them correctly. The following is a simplified section of my code in three different files. My code: Main.js prevItem = () => { console.log(\"Div is clicked\") } render(){ return (