substance / lens

Lens - open science content creation and display
http://substance.io/lens
MIT License
124 stars 20 forks source link

Find a better solution to update the contextId prop of the Scrollbar #49

Open michael opened 8 years ago

michael commented 8 years ago

Currently we solve it like this:

In lens_writer.js:


  this.handleStateUpdate = function(newState) {
    // var oldState = this.state;
    var doc = this.getDocument();

    function getActiveNodes(state) {
      if (state.citationId) {
        var targets = doc.get(state.citationId).targets;
        return [ state.citationId ].concat(targets);
      }
      return [];
    }

    var activeAnnos = getActiveNodes(newState);
    // HACK: updates the highlights when state
    // transition has finished
    setTimeout(function() {
      doc.setHighlights(activeAnnos);  
    }, 0);
  };

And in content_panel.js it's also a bit smelly:

  this.onHighlightsUpdated = function(highlights) {
    var controller = this.context.controller;

    // Triggers a rerender
    this.refs.scrollbar.extendProps({
      highlights: highlights,
      contextId: controller.state.contextId
    });
  };

We do this just to reach some proper coloring of the scrollbar according to the current context. Maybe we find better solution.