Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'd like to add support for an ES6 syntax #335

Open
ringzhz opened this issue Mar 19, 2016 · 7 comments
Open

I'd like to add support for an ES6 syntax #335

ringzhz opened this issue Mar 19, 2016 · 7 comments

Comments

@ringzhz
Copy link

ringzhz commented Mar 19, 2016

Hello, I'd like to work with you to add es6 class-based syntax for driver/robot definitions.
Have you already considered/done it?

@deadprogram
Copy link
Member

Hi, @ringzhz considered yes, but implemented, not yet.

An ES6 class based syntax for adaptors and/or drivers would be fantastic.

We also need to write some examples of robots using ES6 syntax, which is quite simple to do.

In any case, your contributions would be greatly appreciated!

@deadprogram
Copy link
Member

As a simple example of a robot with ES6 syntax:

import * as Cylon from "cylon"

Cylon.api()

Cylon.robot({
  name: "test",

  connections: {
    looper: { adaptor: "loopback" }
  },

  devices: {
    pinger: { driver: "ping" }
  },

  work() {
    every((1).seconds(), () => {
      console.log("Hello, human!")
      console.log(this.pinger.ping())
    })

    after((5).seconds(), () => console.log("It has been 5 seconds"))
  }
})

Cylon.start()

@ringzhz
Copy link
Author

ringzhz commented Mar 20, 2016

That's cool. I think that getting to that place would be fairly easily achievable with the use of a transpiler.

I was thinking something a little more OO like:

import {Robot} from 'cylon';

export class DavesRobot extends Robot {
  // name may be an argument to Robot's constructor?
  getConnections() {
    return {
      looper: { adaptor: "loopback" }
    };
  }
  getDevices() {
    return {
      pinger: { driver: "ping" }
    };
  }
  work() {
    // ...
  }
}

This may require some modifications to the way your code is set up. I haven't looked through your source yet, but do you think that would be a worthwhile improvement?

@deadprogram
Copy link
Member

The place that sort of thing becomes much more useful, IMO, is the creation of adaptors/drivers, where they already are using some inheritance by design.

@ringzhz
Copy link
Author

ringzhz commented Mar 20, 2016

Absolutely, and I just figured it would make sense to follow a similar pattern in the robot code, but indeed, the drivers are where I think this change would make the biggest improvement to code readability/terseness.

@deadprogram
Copy link
Member

The place in the robot code where ES6 would really shine, would be using Promises to control the sequence of events, especially those triggered by every and after. But indeed, other opportunities for syntactical sugar may become apparent.

So you are "in"? 😄

@ringzhz
Copy link
Author

ringzhz commented Mar 20, 2016

For sure. Glad we're on the same page. I'll start taking a look at your codebase when I get a chance and see if I can get a feel for it. Thanks for the prompt responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants