Chart.js: Reorganize internal dependencies

Created on 9 Jul 2017  ·  6Comments  ·  Source: chartjs/Chart.js

The actual code base doesn't import features but fully relies on Chart.* (e.g. Chart.helpers, Chart.defaults, etc...). Files are imported in chart.js in the order they are supposed to depend from each other. As far as I tried, this makes very complicated to safely and properly import a subset of the library.

We could reorganize the library to use require('path/to/features') instead of Chart.{feature} and so remove all function export and Chart.* references.

var helpers = require('../helpers');    // instead of = Chart.helpers
var defaults = require('../defaults');  // instead of = Chart.defaults
//...

The Chart namespace would be fully populated in chart.js:

// chart.js
var Chart = require('./core/core.controller');
Chart.defaults = require('./core/core.defaults');
Chart.helpers = require('./helpers/index');
Chart.controllers = require('./controllers/index');
// ...

Removing the "function export" impacts a lot of lines (remove one tab almost everywhere), so we could do that step by step to avoid huge and painful reviews and limit conflicts with open PRs. I would sequentially split the work as follows:

  • [x] #4479 export Chart.helpers.*, import src/helpers/index
  • [x] #4512 export Chart.defaults.*, import src/core/core.defaults
  • [ ] #5114, #5382, #5969 export Chart.* from core classes
  • [x] #4540 export Chart.elements.*, import src/elements/index
  • [x] #5871 export Chart.controllers.*, import src/controllers/index
  • [x] #5953 export Chart.scales.*, import src/scales/index
  • [x] #4509 export Chart.platform.*, import src/platform/platform
  • [x] #5114 export Chart.plugins.*, import src/plugins/index
  • [x] #5868 deprecate Chart.* (from `src/charts/*.js)

This is a preliminary work in order to migrate to ES6 modules (discussed in #2466, #4461, #4303, etc.). Awesome work as been done by @salzhrani but I believe that trying to do everything in one step (including ES6 new features) will take time, be hard or even impossible to review / handle conflicts with incoming contributions and finally takes forever to land in master.

Thoughts?

enhancement

Most helpful comment

Any progress on this?

All 6 comments

This is super awesome.
I would also suggest switching to rollup once all is done.

It's planned :)

Any progress on this? I'd love to see this one added to the 2.8 milestones! 👍

@pndewit would be a nice feature, unfortunately both @simonbrunel and I are crazy busy right now so we aren't able to do it ourselves.

Any progress on this?

The code uses import everywhere now, so I'm going to consider this done. https://github.com/chartjs/Chart.js/pull/6935

Was this page helpful?
0 / 5 - 0 ratings