npm,ecmascript-6,jspm,systemjs,es7 , Can anyone explain what es7 reflect-metadata is all about?


Can anyone explain what es7 reflect-metadata is all about?

Question:

Tag: npm,ecmascript-6,jspm,systemjs,es7

Been studying ES6, JSPM & angular2 for a week now and I found this repo ES6-loader

if we look at the index.html at the bottom script you'll see

 System.import('reflect-metadata')
  .then(function() {
    return System.import('app/index');
  })
  .catch(console.log.bind(console));

This is using JSPM's systemjs polyfill to get ES6's import.

Question: What is the reflect-metadata really do in this situation? npm reflect-meta The more I read the documentation, the less I understand what it does?


Answer:

'reflect-metadata' is a package that is a proposal for ES7. It allow for meta data to be included to a class or function; essentially it is syntax sugar.

Example. Angular 2 ES6:

@Component({selector: "thingy"})
@View({template: "<div><h1>Hello everyone</h1></div>"})
class Thingy{};

As you can see there are no semicolons after @Component and @View. This is because they are essentially Chains of (meta)data on the class.

Now lets look at that same code in Angular 2 but in ES5:

function Thingy(){}
Thingy.annotations = [
    new angular.ComponentAnnotation({
        selector: "thingy"
    }),
    new angular.ViewAnnotation({

        template: "<div><h1>Hello everyone</h1></div>"
    })
];

As you can see the @ symbol abstracts out alot of the annotations property of a class and makes it More D.R.Y.

Taking this one step further Angular team knows that annotations are a bit abstract for the new user. Moreover, the ES5 is just too verbose. which is why they made a.js which will make interfacing with annotations better:

Video to understand this


Related:


Symbol.for(string) in ECMAScript 6


javascript,symbols,ecmascript-6
It took me a while but I finally figured out what the purpose of symbols in ECMAScript 6 is: avoiding name collision when attaching properties to shared objects - HTML elements e.g. (In case you're stuck on the same question, I recommend this article.) But then I stumbled upon Symbol.for()....

jsx command not found on mac terminal


node.js,npm,reactjs,jsx
Problem: I execute the following command from the macintosh terminal: $ jsx --watch src/ build/ I recieve the following output error from the terminal: -bash: jsx: command not found Relevant information: I am following the following tutorial: https://facebook.github.io/react/docs/getting-started.html I executed the following command from the tutorial with positive output: $...

Is there any way to modify a Set data structure in iteration (ECMAScript 6)?


ecmascript-6
The Set object in ES6 has a forEach method, just like Array object does. Is there any way to modify the values when iterating over the Set object using the forEach method? For example: // Array object in ES5 can be modified in iteration var array = [1, 2, 3];...

NPM Error: self signed certificate in certificate chain


ssl,npm,tsd
I am following the Angular 2 quick start guide and I'm stuck right at the beginning of it. My company is filtering our network connections and modifying SSL negociation. In a man in the middle style they assign a self signed certificate as the CA of the destination's certificate. Therefore...

ES6 destructuring, dynamic assignment [duplicate]


javascript,ecmascript-6
This question already has an answer here: object destructuring without var 1 answer let text, value; if (typeof f == 'string') { text = value = f; } else { let { text, value } = f; } Doing this creates two new vars (from the else), however if...

Aurelia update value of bound item in another class


ecmascript-6,aurelia
I guess the question boils down how to i pass the instance of a property to another class. I have something like this: import timerClass from "./timer"; export class App { constructor() { this.timeLeft = 6; //<--- I want to update this new timerClass(this.timeLeft); } activate() { } } and...

Node js can't require modules installed globally in OS X


node.js,osx,npm
I installed module by sudo npm install -g xxx in OS X, and the command echoes the module was installed in /usr/local/lib/node_modules/xxx. But the require('xxx') still fails claiming `Cannot find module 'xxx'. Only installing the module locally again by sudo npm install xxx can fix the error. Anything need to...

How to let Webpack require a root node_module instead of an child package?


backbone.js,npm,webpack
I have installed backbone and backbone.babysitter trough npm. When I use backbone in my scripts like this: import Backbone from "backbone"; It loads the installed backbone version 1.2.1. This works fine until I want to use backbone.babysitter. When backbone.babysitter loads it needs to add properties to backbone itself. But the...

ES6 Iterate over class methods


javascript,ecmascript-6
Given this class; how would i iterate over the methods that it includes? class Animal { constructor(type){ this.animalType = type; } getAnimalType(){ console.log('this.animalType: ', this.animalType ); } } let cat = window.cat = new Animal('cat') What I have tried is the following with no success: for (var each in Object.getPrototypeOf(cat)...

Why should I use ES6 classes? [closed]


javascript,ecmascript-6
I have many question about ES6 classes. Since i understand how to use function and WebComponent, React & so. I didn't see many benefit using it. I wonder what's the benefit of using classes. I read that public/private/static will be part of ES7. So i see no point using it...

ES6 - Convert from 'require' to 'import'


ecmascript-6
If the alternative to: var Foo = require('foo'); is: import Foo from 'foo'; What is the alternative to: var Bar = require('foo').batz Could it be: import {batz} from 'foo' ? ...

why obj={x,y} works in Chrome?


javascript,ecmascript-6
var obj = { type: 'data', x, y, data: []} Obviously this was my typo, {x,y} should have been {x:x, y:y}. But it does what I want, in Chrome, field x gets the value of a local variable x. But why does it work?...

How does `this` work in default parameters?


javascript,ecmascript-6
So... ES6¹ (which happens to be standardized a few hours ago) brings default parameters for functions similar to those in PHP, Python etc. I can do stuff like: function foo (bar = 'dum') { return bar; } foo(1); // 1 foo(); // 'dum' foo(undefined); // 'dum' MDN says that the...

Combine js files from different directories via config using grunt


javascript,gruntjs,npm,minify
I'm using grunt and sass and I'm looking for a sass-like feature to import any JS file I like to and combine them to 1 file via some config depending on the directory I am in. Example directories: startpage file1.js file2.js importjs.json page1 file3.js file4.js importjs.json global global1.js global2.js Each...

Error: EMFILE: too many open files


javascript,node.js,request,npm
Using nw.js, I am just trying to save images in an array of img elements with different random names. But having a few errors, is something wrong with my code? for (i = 0; i < imgs.length; i++) { request(imgs[i].getAttribute('src')).on('error', function(err) { throw err }).pipe(fs.createWriteStream('data/imgs/' + randomString)) } imgs[] is...

ECMAScript class


javascript,ecmascript-6
I have the following code which when the web page loads should print the car make and current speed to the console. Nothing is printed to the console. If I put the new object declaration inside a function it does print either. <!DOCTYPE html> <html> <head> <script type="application/ecmascript;version=6"> class Car...

Created a package.json file, but getting dependency errors when running npm install


javascript,json,node.js,npm
I know this is a common question and I tried researching on here, but none of the answers have seemed to help me thus far. I am following this tutorial to learn node, and after I try to install the package.json I received the following errors: npm ERR! install Couldn't...

how to correctly use promises to return 2 different results [duplicate]


javascript,promise,ecmascript-6,es6-promise
This question already has an answer here: How do I access previous promise results in a .then() chain? 6 answers I am trying to use Promises in JavaScript using ES6 to return data from 2 methods from an object, which would in production call out to an endpoint. My...

node user model is vomitting


node.js,express,npm
I am trying to get my hands dirty with making node api following this tutorial https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens problem is that when I execute $ nodejs server.js I get this error { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version {...

“Import” ES6 for Node


javascript,node.js,ecmascript-6
I want to use import from ES6 rather than require from common.js in Node. For some reason I thought import would work by default in Node. But looks like it does not. Is there some npm package i need to install for that to work?

lodash npm distribution in browser


npm,karma-runner,bower,lodash
I'm using lodash in my tests, Not using webpack or browserify (don't need to). I found that the default npm build differs from what's in bower. I could of course use bower version, but I'm curious if I can use npm's instead (it's already there for Gulp). For bower I...

NPM : how to just run post-install?


node.js,npm,package.json
Just a simple question : in my node.js project, how could I just run the postinstall script, without running install before ? FYI, this is my package.json : { "name": "gestionclientjs", ..., "dependencies": { ... }, "repository": {}, "devDependencies": { ... }, "engines": { "node": ">=0.10.0" }, "scripts": { "test":...

Obj-C category/extension Swift in Javascript ES6


javascript,ecmascript-6
I'm looking to add methods to a class in Javascript ES6 without creating a subclass of it, in the same way with the categories in Objective-C or extensions in Swift. I didn't find any information about it. Any suggestion?...

Npm package upgrade notification availlable?


node.js,npm,packages,software-distribution
I wrote a node package which contains breaking changes in the next release. Does there exist a way to notify developers about that via console while upgrading via npm?

React from NPM cannot be used on the client because 'development' is not defined. The bundle was generated from Webpack


javascript,node.js,npm,reactjs,webpack
I'm creating a React Node.js app and I'm trying to generate a Webpack bundle containing the React source code I loaded from NPM. However, it seems that the React code from NPM cannot be used directly in the client. It triggers this error: Uncaught ReferenceError: development is not defined The...

Include paths for imports in babel using webpack


ecmascript-6,webpack,babeljs
Given a directory structure such as: project ├───common │ └───js └───src └───js is there any way to add import paths to webpack so that a script inside src/js can resolve code inside common/js if it cannot find anything else locally? Something like the code below would include common/js/CommonClass.js: import CommonClass...

Angular 1.4 + ngNewRouter + ES6 : Cannot read property '$routeConfig' of undefined


angularjs,ecmascript-6,angular-new-router
I am currently trying to throw together a basic working example of an Angular 1.4 app written with both the new router as well as ECMAScript 6. I have been fiddling with this code non stop and I don't understand why I am getting the error that is being thrown:...

npm installs packages and dependencies in the project root directory


node.js,npm
I switched from Windows to Mac. When I'm trying to install npm modules, the packages and their dependencies are created inside the project root directory. On Windows the module was installing into ./node_modules, with all dependencies inside module folder. Is there something I need to configure to make it work...

NPM Error Parsing Json, Unexpected Token


json,node.js,npm
I'm trying to install grunt, but no luck. npm install -g grunt-cli --registry http://registry.npmjs.org/ gives this error: npm ERR! registry error parsing json npm ERR! Darwin 14.3.0 npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli" "--registry" "http://registry.npmjs.org/" npm ERR! node v0.12.4 npm ERR! npm v2.10.1 npm ERR! Unexpected token <...

Create a subset object, consisting of only some of the properties of an existing object


javascript,ecmascript-6
This is best explained by example. The following works in es6 to create an object consisting of some of the keys of an existing object: var o = {a:1, b: 2, c: 3} var {a, c} = o var subsetObj = {a, c} // will be: {a:1, c:3} There are...

ServiceWorker and Push Notification Payload


node.js,android-gcm,ecmascript-6,service-worker,chrome-gcm
Community: ServiceWorker is a great advance technology in terms of cache managment, but I have some questions associated with other operations such as: Push Notification: I made a GCM integration (Google Clud Message) and NodeJS, following this article, the problem is that when GCM sends the information to the client...

Executing promises in sequence: understanding a claim made about this example code


javascript,promise,ecmascript-6
I'm not looking for a solution for how to execute promises in sequence, I'm trying to understand the one given by a blog author: I am reading "We have a problem with promises" by Nolan Lawson, posted 18 May 2015. Under "Advanced mistake #3: promises vs promise factories" he has...

IntelliJ/Webstorm not finding import reference


javascript,intellij-idea,phpstorm,webstorm,ecmascript-6
I have the following project structure: root src scripts main.js foo.js Inside of my main.js file, I'm importing foo.js like so: import 'src/scripts/foo.js' When I click on the import statement above and go to Navigate -> Declaration I get a super helpful message that says Cannot find declaration to go....

sass file not compiled by gulp


css,node.js,sass,npm,gulp
I want to switch from less to sass so I installed gulp-sass with npm and modified my gulpfile to compile sass instead of less (nothing else changed). Sadly gulp doesn't compile my .scss file to css and after googling and trying all i could think of it still doesn't compile....

Using String.raw() with Node JS


javascript,node.js,ecmascript-6
I'm working on a Node.js app with and I would like to use String.raw() which is part of the ES 6 standard. However, when using it as in the documentation: text = String.raw`Hi\n${2+3}!` + text.slice(2); It returns SyntaxError: Unexpected token ILLEGAL for the character after String.raw. I think that there...

Dynamic key in immutability update helper for array


javascript,reactjs,ecmascript-6
https://facebook.github.io/react/docs/update.html I have an update function that receives an index along with the event so as to alter the value for that specific item in the array. How do I get index to be evaluated instead of treated as a set key in this scenario? Is it even possible? updateValue:...

Do I have to call super.componentDidUpdate in React?


reactjs,ecmascript-6
In a subclass of React.Component, do I have to call super.componentDidUpdate from my componentDidUpdate method? Or is it done automatically? (I am trying to call it but there is an error message Cannot read property call of undefined)...

Explanation of `let` and block scoping with for loops


javascript,ecmascript-6
I understand that let prevents duplicate declarations which is nice. let x; let x; // error! Variables declared with let can also be used in closures which can be expected let i = 100; setTimeout(function () { console.log(i) }, i); // '100' after 100 ms What I have a bit...

VS 2015 RC - Trying to fetch local plugin from remote registry


node.js,npm,cordova-plugins,visual-studio-cordova,plugman
I have a local plugin, which I'm trying to install to a Cordova project. Adding it through VS works like a charm, but when I'm building it, plugman tries to retrieve the plugin from the registry (npm http GET http://registry.cordova.io/[Plugin]/[Version]) and the build fails, because this plugin only exist locally....

404 on api authenticate for node restful


node.js,express,npm
I am using this tutorial https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens to learn about node with restful authentication. I am getting 404s in the route when I post at this http://localhost:8090/api/authenticate Here is the response that I get Cannot POST /api/authenticate and the console shows 404 POST /api/authenticate 404 2.465 ms - 30 here is...

Node.js app giving ERR_EMPTY_RESPONSE


javascript,node.js,mongodb,npm
I'm having serious issues with an app I am building with Node.js, Express, MongoDB and Mongoose. Last night everything seemed to work when I used nodemon server.js to `run the server. On the command line everything seems to be working but on the browser (in particular Chrome) I get the...

How to create web client application with nodejs and npm like angularjs tutorial


javascript,angularjs,node.js,npm
I am new to nodejs, npm also angularjs. I have read and tried the angularjs tutorial project hosted on https://github.com/angular/angular-phonecat.git, which for me is really exciting because it shows how easy to maintain the modules with bower, testing with jasmine and karma and perform e2e with protractor using npm command,...

ES2015 Babel String Interpolation not working with apostrophe (but does with double quotes)


javascript,ecmascript-6,babeljs
I am using babel / grunt to learn some ES2015. According to this post there is no real difference in Javascript between single and double quotes. i.e. 'test' and "test". When trying string interpolation though, it seems there is an issue with babeljs (or more likely - me). What is...

How to get a last element of ES6 Map without iterations?


containers,ecmascript-6
How to get a last element of ES6 Map/Set without iterations(forEach or for of) pass through a full length of the container?

React components as plain JS objects?


javascript,class,reactjs,javascript-objects,ecmascript-6
Does anybody has experience in working with React components as plain JS objects instead of annoying ES6 classes and deprecated .createClass method. Maybe you have some examples of factory functions or similar to share? Thanks!...

npm install error not installing BrowserSync package


node.js,cmd,npm,command-prompt,browser-sync
Trying to install BrowserSync I've followed the steps to install the package through the command line, installed node.js and then I went on to install npm through the command line. Now when I try to install browser-sync with the following line npm install -g browser-sync you will see it is...

MongoDB Object key with ES6 template string


javascript,mongodb,ecmascript-6
I'm trying to update an array in my collection with this: var str = "list.0.arr"; db.collection('connect').update({_id: id}, {$push: { `${str}`: item}}); This exact string works just fine if I do it like this: db.collection('connect').update({_id: id}, {$push: { "list.0.arr": item}}); This is to show that it works, but It's throwing an...

Proper npm install --save behavior?


npm
All documentation I have seen indicates that using --save argument with npm install should update the dependencies in package.json. This does not work for me. Packages install successfully without any error in the npm console output, but `package.json' remains unchanged. What am I missing? I have seen nothing in my...

Writing the most basic Unit test in Angular 2?


javascript,unit-testing,karma-runner,ecmascript-6,angular2
Problem: As soon as I import Angular 2 into a file none of my tests execute. Question: How can I set up my karma config to support angular two so my test pass properly? OR Question: How can I set up any testing framework with angular2 written in es6? Git...

Input validation setTimeout in ReactJS


javascript,css,validation,reactjs,ecmascript-6
I have a component that renders with className="error" or classname="" depending on whether the input is valid or not. This way in CSS I can simply do .error { background: red; }. The validity of the input is determined by the isValidNumber(..) function. However, right now the problem I'm having...