MariusRumpf / node-lifx

Node.js implementation of the LIFX LAN protocol :bulb:
MIT License
144 stars 28 forks source link

ES6 syntax #39

Closed kenziesimpson closed 8 years ago

kenziesimpson commented 8 years ago

How would I be able to import this with ES6 syntax, seeing as by default you are supposed to use a require statement like so:

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

client.init();

How would you do this with ES6 syntax?

MariusRumpf commented 8 years ago

ES6 import syntax can only be used with transpiling for now and is not native so far. I would think something like this might work (not tested):

import {Client as LifxClient} from 'node-lifx';
const client = new LifxClient;

client.init();

Does this work for you?

jshimko commented 8 years ago

You should be able to just import the default with:

import LifxClient from 'node-lifx';

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

kenziesimpson commented 8 years ago

I'm pretty sure the second way worked for me. Thanks!