• Robert Knight's avatar
    Make Sidebar collaborate with rather than inherit from Guest · b52f00e0
    Robert Knight authored
    Change the relationship between the `Guest` and `Sidebar` classes from
    one of inheritance to one where `Sidebar` receives a reference to the
    `Guest` instance and calls methods on it or subscribes to events from
    it. The `Guest` also no longer "owns" references to the bucket bar /
    toolbar objects that logically belong to the sidebar. Instead it emits
    events which the sidebar responds to.
    
    This change makes the interface of the `Guest` used by the `Sidebar`
    more explicit and ensures a better boundary between the two. This also
    makes it easier for the `Sidebar` tests to be concerned only with the
    interface of the `Guest` and not its implementation details. In future
    this change will also make it possible to have a frame which does not
    contain a sidebar but is not annotateable. We had a need for this
    historically when integrating with epub viewers, although it was never
    implemented.
    
    Updating the tests for `PdfSidebar` was complicated by the fact that the
    `PdfSidebar` tests are not pure unit tests. They instantiate the
    `Sidebar` base class and so depend on many implementation details of it.
    To make this change and others easier, the `PdfSidebar` tests have been
    changed to mock the `Sidebar` base class. The steps involved in this are
    non-obvious so I extracted the logic into a utility function.
    
     - Change `Sidebar` to no longer inherit `Guest` but accept it as a
       constructor argument
     - Remove direct references to the `BucketBar` and `ToolbarController`
       instances from the `Guest` class and instead emit events from the
       `Guest` which the `Sidebar` responds to.
     - Add a `mockBaseClass` testing helper in `src/test-util/mock-base.js`
       and change the `PdfSidebar` tests to use it, so that they are less
       coupled to `Sidebar` implementation details.
    b52f00e0
Name
Last commit
Last update
..
anchoring Loading commit data...
components Loading commit data...
config Loading commit data...
plugin Loading commit data...
test Loading commit data...
util Loading commit data...
.eslintrc.js Loading commit data...
adder.js Loading commit data...
annotation-counts.js Loading commit data...
annotation-sync.js Loading commit data...
bucket-bar.js Loading commit data...
delegator.js Loading commit data...
features.js Loading commit data...
frame-observer.js Loading commit data...
guest.js Loading commit data...
highlighter.js Loading commit data...
icons.js Loading commit data...
index.js Loading commit data...
notebook.js Loading commit data...
pdf-sidebar.js Loading commit data...
pdfjs-rendering-states.js Loading commit data...
range-util.js Loading commit data...
selection-observer.js Loading commit data...
sidebar-trigger.js Loading commit data...
sidebar.js Loading commit data...
toolbar.js Loading commit data...