Skip to content

Commit

Permalink
Rerun Octo-Linker when blobs are expanded (#505)
Browse files Browse the repository at this point in the history
<!--
  Thanks for filing a pull request!

  Please look at the following checklist to ensure that your PR
  can be accepted quickly:
-->

This is a possible implementation for #453, we observe the DOM, if any new `.blob-expanded` nodes are added, then the extension is rerun.

As far as testing goes, I will wait for feedback, I added a single test that clickes the specific `.js-expand` element and then tries to process a single line from it.

### Checklist:

- [ ] If this PR is a new feature, please provide at least one example link
- [x] Make sure all of the significant new logic is covered by tests
  • Loading branch information
leomoty authored and stefanbuck committed Aug 29, 2018
1 parent 38dd5c8 commit 9ed3ebc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions e2e/automated.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ describe('End to End tests', () => {
});
});
});

describe('expanded blob', () => {
it('should resolve after appending new blobs', async () => {
const url =
'https://github.com/OctoLinker/OctoLinker/pull/451/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2';
const selector = '[data-line-number="45"] + td .octolinker-link';
const expandSelector = '[data-right-range="44-55"]';

await page.goto(url);

await page.click(expandSelector);

await page.waitForSelector(selector);
});
});
});
11 changes: 11 additions & 0 deletions packages/core/octo-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,23 @@ async function run(self) {
clickHandler(matches);
}

function observeExpand(self) {
const observer = new MutationObserver(() => {
run(self);
});

for (const el of document.querySelectorAll('.diff-table tbody')) {
observer.observe(el, { childList: true });
}
}

export default class OctoLinkerCore {
constructor(options) {
initialize(this, options);
}

init() {
injection(run.bind(null, this));
observeExpand(this);
}
}

0 comments on commit 9ed3ebc

Please sign in to comment.