dmill-bz / gremlin-console-js

A gremlin console for browsers. This console can connect either directly to gremlin-server or serve requests through a intermediary page via AJAX.
Other
21 stars 9 forks source link

Homogenize browser and node calls #4

Open dmill-bz opened 8 years ago

dmill-bz commented 8 years ago

@jbmusso I'm going to need your help one more time (sorry for the trouble).

I'm basically almost done. Once the two issues here are taken care of and I replace the current code on gremlin-bin to use this library (which should be the last use case I need to be confident in the lib). I'll move this into 1.0.0.

The help I need is in regards to the difference between the calls in these two implementations (took this from one of the plugin's docs) :

Using ES2015/2016

import GremlinConsole from 'gremlin-console';
import GCGraphSONTextPlugin from 'gc-graphson-text-plugin';

//create a console + input combo by passing css selectors to GremlinConsole
const gc = GremlinConsole('#console-window', '#console-input');
gc.register(GCGraphSONTextPlugin()); //register the plugin

In browser

//create a console + input combo by passing css selectors to GremlinConsole
var gc = GremlinConsole.create('#console-window', '#console-input');
gc.register(GCGraphSONTextPlugin.init()); //register the plugin

As you can see there's nothing homogenous about the two. I would like to make the browser implementation the same as the other. I've tried playing around with webpack.config.babel.js without success. I know that's the right place but I can't seem to pull it off. Any ideas?

Thanks a ton.

jbmusso commented 8 years ago

Chunking through tons of unread emails, sorry about the late reply.

I think using export default create in index.js is what causes the issue here.

export default defines what will be imported when you do import foo from 'module'. foo will be anything you decide to export after that export default statement.

You're simultaneously doing export const create = () => { and doing a default export of that same create function. With the current setup (if you skip the export default for now), you can do this:

import * as GremlinConsole from 'gremlin-console-js';

// OK:
GremlinConsole.create()

An alternative way is to export default an Object rather than a function

export default {
  create
}

// equivalent to export default { create: create } thanks to a syntax shorthand

which allows you to import the create function in the following way

import { create } from 'gremlin-console-js';

I think https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export will give better insights.

dmill-bz commented 8 years ago

Thanks!! I'll have a look and try at it again.