Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gather urls while initializing extension #448

Merged
merged 3 commits into from
Mar 5, 2018

Conversation

stefanbuck
Copy link
Member

@stefanbuck stefanbuck commented Feb 19, 2018

This is another PR down the road to resolve all links on start-up. With this PR we still lazy load the url on click, but upfront we gather all possible urls and cache the results on start-up. I changed the signature of plugin.resolve() for consistency and readability which leads to a bigger PR size. All critical changes are made in the first commit. I hope it's not to bad to review.

@@ -1,153 +0,0 @@
import assert from 'assert';
Copy link
Member Author

Choose a reason for hiding this comment

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

In another PR I'll get rid of click-handler at all. I think it's okay to not spent time on fixing the test. I did manual QA on this anyway.

$body.undelegate(LINK_SELECTOR, 'click', onClick);
$body.undelegate(LINK_SELECTOR, 'mouseup', onClick);

$body.delegate(LINK_SELECTOR, 'click', onClick);
$body.delegate(LINK_SELECTOR, 'mouseup', onClick);

pluginManager = _pluginManager;
matches = _matches;
Copy link
Member Author

Choose a reason for hiding this comment

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

For simplicity I tweaked the click-handler according to my needs. As mentioned above, it will go away soon.

link.dataset[key] = data[key];
}
}
});
Copy link
Member Author

@stefanbuck stefanbuck Feb 19, 2018

Choose a reason for hiding this comment

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

We used data-attributes to hold a reference to the plugin and other plugin related informations. Now we pass the plugin itself down which makes things a lot easier.

export default function(el, regex, mapping, captureGroup = '$1') {
if (!(el instanceof HTMLElement)) {
throw new Error('must be called with a DOM element');
export default function(blob, regex, plugin, meta = {}) {
Copy link
Member Author

@stefanbuck stefanbuck Feb 19, 2018

Choose a reason for hiding this comment

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

meta can be used to pass additional informations down to the resolver function. Right now this is only used by the bower and npm manifest plugin to distinguish between different resolver behaviour see https://github.com/stefanbuck/OctoLinker/blob/850801fd5e2cfd91db428e3f0173956c03c756aa/packages/plugin-npm-manifest/index.js#L13-L25

@stefanbuck stefanbuck force-pushed the call-resolvers-upfront branch from 850801f to a2348df Compare February 19, 2018 23:22
}

export default {
name: 'NpmManifest',

resolve({ target, path, type }) {
resolve(path, values, { type }) {
Copy link
Member Author

@stefanbuck stefanbuck Feb 20, 2018

Choose a reason for hiding this comment

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

The resolve function receives the RegExp result as the second argument in order to get rid of the captured group ($1, $2 ...) magic. In most of the cases you are interested the first value only.

In some rare cases like this npm plugin, you need to differentiate based on the value the next step e.g. calling resolver with different values.

@stefanbuck
Copy link
Member Author

@josephfrazier I added a few comments, I hope this helps reviewing this PR. Please don't hesitate to ask if something is still unclear.

@josephfrazier
Copy link
Member

I won't say I completely understand all the changes yet, but I don't have to ;). I did a smoke-test and it seems fine, so feel free to merge. I'm not sure whether you want to squash or rebase, so I'll leave it up to you.

@stefanbuck
Copy link
Member Author

I can imagine, that looking at all this changes ins't easy. I tried to keep it as simple as possible. Thanks for the review

@stefanbuck stefanbuck merged commit 6a5afda into OctoLinker:master Mar 5, 2018
@stefanbuck stefanbuck deleted the call-resolvers-upfront branch March 5, 2018 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants