question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrate code base to ES6

See original GitHub issue

As of version 1.0.0 this library exposes ES modules. We use bundler such as Webpack or Rollup to bundle library

Why are we still using es4 syntax with prototypes? All modern browsers support es5 at least.

Even if we want support old ones in any case we use webpack for bundling.

For example, we can change this “class”:

import {
  create
} from '../model';

import { assign } from 'min-dash';

/**
 * A factory for diagram-js shapes
 */
export default function ElementFactory() {
  this._uid = 12;
}


ElementFactory.prototype.createRoot = function(attrs) {
  return this.create('root', attrs);
};

ElementFactory.prototype.createLabel = function(attrs) {
  return this.create('label', attrs);
};

ElementFactory.prototype.createShape = function(attrs) {
  return this.create('shape', attrs);
};

ElementFactory.prototype.createConnection = function(attrs) {
  return this.create('connection', attrs);
};

/**
 * Create a model element with the given type and
 * a number of pre-set attributes.
 *
 * @param  {string} type
 * @param  {Object} attrs
 * @return {djs.model.Base} the newly created model instance
 */
ElementFactory.prototype.create = function(type, attrs) {

  attrs = assign({}, attrs || {});

  if (!attrs.id) {
    attrs.id = type + '_' + (this._uid++);
  }

  return create(type, attrs);
};

to the modern one:

import {
  create
} from '../model';

import { assign } from 'min-dash';

/**
 * A factory for diagram-js shapes
 */
export default class ElementFactory {
  constructor() {
    this._uid = 12;
  }

  createRoot(attrs) {
    return this.create('root', attrs);
  }

  createLabel(attrs) {
    return this.create('label', attrs);
  }

  createShape(attrs) {
    return this.create('shape', attrs);
  }

  createConnection(attrs) {
    return this.create('connection', attrs);
  }

  /**
   * Create a model element with the given type and
   * a number of pre-set attributes.
   *
   * @param  {string} type
   * @param  {Object} attrs
   * @return {djs.model.Base} the newly created model instance
   */
  create(type, attrs) {

    attrs = assign({}, attrs || {});

    if (!attrs.id) {
      attrs.id = type + '_' + (this._uid++);
    }

    return create(type, attrs);
  }
}

I can do the most migration by myself, but will it be ever merged?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
nikkucommented, Aug 29, 2020

By the way, class is an ES6, not a ES5 feature 😉.

0reactions
nikkucommented, Feb 11, 2021

As of Q1 2021 we get proper IDE tooling if we fix our JSDoc annotations.

Closing this issue, as introducing classes will be a major breaking change that we’ll likely not act upon in the near future.

Related: https://cdn.statically.io/gh/nikku/types-without-typescript/v0.0.2/presentation.html.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating an old JavaScript codebase to modern JavaScript
Bring our code to a point where we can start refactoring it. · Bundle our JavaScript using Webpack, so we can minify it...
Read more >
Migrating old-style JavaScript code to ES6 - Pejibaye Blog
Recently (at work) I had to migrate a medium-sized JavaScript codebase (20KLOC) to ES6. We wanted to migrate to take advantage of the...
Read more >
Migrating from CoffeeScript to JavaScript (ES6) - Medium
When your codebase is big, deciding to start using ES6 instead of CoffeeScript sounds scary. It should not be: the key point is...
Read more >
Converting a large React Codebase from Coffeescript to ES6
A strategy for conversion​​ We require that all new modules must be written in javascript. Any existing coffeescript files should be converted if ......
Read more >
Automated Refactoring of Legacy JavaScript Code to ... - arXiv
In this paper, we propose a fully-automated method for migration of an. ES5 codebase to ES6 modules. The method applies to code that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found