Skip to content

Conversation

@simonbrunel
Copy link
Member

@simonbrunel simonbrunel commented Jun 10, 2016

Mostly explained in commit messages, but on the menu:

  • Renamed Chart.pluginService to Chart.plugins,
  • Renamed Chart.pluginService.remove to Chart.plugins.unregister,
  • Renamed Chart.pluginService.notifyPlugins to Chart.plugins.notify,
  • Can now register/unregister an array of plugins,
  • Changed the notify behavior to return false as soon as a plugin explicitly returns false (can be used, for example, to cancel an action),
  • Introduced 2 new extensions: beforeDatasetsUpdate (cancellable) and afterDatasetsUpdate,
  • Renamed before/afterDatasetDraw to before/afterDatasetsDraw (with s to Datasets),
  • Updated plugins related unit tests.

Note: I need these changes to implement a plugin to address #2745

Rename `Chart.pluginService` to `Chart.plugins` (so move the old Chart.plugins array as a private member of the service), and rename `notifyPlugins` to `notify` for consistency with other service methods.
Change the plugin notification behavior: this method now returns false as soon as a plugin *explicitly* returns false, else returns true. Also, plugins are now called in their own scope (so remove the never used `scope` parameter).
@simonbrunel
Copy link
Member Author

The plugins service now accepts an array of plugin instances to register or unregister (for consistency, renamed `Chart.plugins.remove` to `unregister`). Also added a few methods to manipulate registered plugins, such as `count`, `getAll` and `clear` (mainly used by our unit tests).
Add `beforeDatasetsUpdate` and `afterDatasetsUpdate` plugin notifications during the chart update. Plugins are able to cancel the datasets update by explicitly returning false to `beforeDatasetsUpdate`. For consistency, rename `(before|after)DatasetDraw` to `(before|after)DatasetsDraw`.
* Unregisters the given plugin(s) only if registered.
* @param {Array|Object} plugins plugin instance(s).
*/
unregister: function(plugins) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for completeness we should implement remove to alias to unregister

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same first but then realized that this method has never been used in code or plugins (correct me if I'm wrong), and I can't see any case where it should be used (except in unit tests). So was thinking that we may not keep compatibility and save a few bits. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't think anyone has used it.

@etimberg
Copy link
Member

etimberg commented Jun 10, 2016

Other than my 1 comment this is good to go

Edit: did not mean to close, sorry

@etimberg etimberg closed this Jun 10, 2016
@etimberg etimberg reopened this Jun 10, 2016
@etimberg etimberg merged commit 647dc58 into chartjs:master Jun 11, 2016
@simonbrunel simonbrunel deleted the plugins-arch branch August 25, 2016 19:19
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

Successfully merging this pull request may close these issues.

2 participants