partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
248 stars 61 forks source link

Is there any documentation on the events that we can subscribe to? #176

Open agjs opened 4 years ago

agjs commented 4 years ago

Hi guys,

Before everything, thanks for the awesome library. While the documentation was pretty helpful, I had a lot of issues figuring how to which events we can subscribe and react to changes.

For instance, I would like to subscribe to Composer changes, meaning, e.g. every time user draws a bond or anything for that matter, I'd like to update a viewer to whatever use has drawn in the editor. Is what I'm explaining possible and are there any other events in general we can utilize for more dynamic behavior (if necessary).

Cheers

partridgejiang commented 4 years ago

Hi @agjs, you can listen to the editObjsUpdated event, evoked when the objects in the editor been changed (even during manipulation, e.g., in dragging), or the operChange event, evoked after a manipulation totally done (e.g., dragging end).

composer.on('editObjsUpdated', function(e){
  viewer.setChemObj(composer.getChemObj());
});
composer.on('operChange', function(e){
  viewer.setChemObj(composer.getChemObj());
});

Note that to utilize the operChange event, operation history should be enabled (this is also the default setting of composer).