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

Move loading logic into each feature #1694

Merged
merged 22 commits into from Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4a7493e
Move loading logic into each feature
fregante Jan 7, 2019
c5edfa6
Make it work on unconditioned features
fregante Jan 7, 2019
4dd2ca8
Make it work on unconditioned features /2
fregante Jan 7, 2019
4833832
Renamed loading functions
fregante Jan 7, 2019
4e9e27c
Error if `definition` props are invalid
fregante Jan 7, 2019
8b71d18
Renamed loading functions /2
busches Jan 8, 2019
74cd801
Renamed loading functions /3
busches Jan 8, 2019
c695295
Include domLoaded in onAjaxedPagesRaw
fregante Jan 8, 2019
740147a
Fix mark-unread
fregante Jan 8, 2019
2271de3
Add formal "deinit" function
fregante Jan 8, 2019
9278d0d
Drop safeElementReady from features
fregante Jan 8, 2019
a670fce
Simplify/fix order between mark-unread and open-all-notifications
fregante Jan 8, 2019
c2317a7
Ensure that onAjaxedPages (safe) marks the real end
fregante Jan 8, 2019
c3b51ba
Import all at once
fregante Jan 8, 2019
94b223b
Revert "Import all at once"
fregante Jan 8, 2019
2fefc23
Add explicit excluded pages; rename `dependencies` to `include`
fregante Jan 14, 2019
bd06e8b
Fix back-button-duplicate-avoider order
fregante Jan 14, 2019
0ddb8d9
Rename domLoaded to domReady to facilitate contributions
fregante Jan 14, 2019
6e82b4d
Add simple and advanced examples for features.add
fregante Jan 14, 2019
0d8c5cd
Restore mistakenly-removed error loggin
fregante Jan 15, 2019
bcc04bb
Minor changes to improve readability
fregante Jan 15, 2019
d2d3a47
Rename domReady to onDomReady for consistency
fregante Jan 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 55 additions & 3 deletions contributing.md
Expand Up @@ -8,11 +8,63 @@ Suggestions and pull requests are highly encouraged! Have a look at the [open is
- The extension can be loaded into Chrome or Firefox manually ([See notes below](#loading-into-the-browser))
- [JSX](https://reactjs.org/docs/introducing-jsx.html) is used to create DOM elements.
- All the [latest DOM APIs](https://github.com/WebReflection/dom4#features) and JavaScript features are available because the extension only has to work in the latest Chrome and Firefox. 🎉
- Each JavaScript feature lives in its own file under [`source/features`](https://github.com/sindresorhus/refined-github/tree/master/source/features) and it's loaded on condition in [`source/content.js`](https://github.com/sindresorhus/refined-github/blob/master/source/content.js).
- Some GitHub pages are loaded via AJAX/PJAX, so some features need to be in the special `ajaxedPagesHandler` function (see it as a custom "on DOM ready").
- See what a _feature_ [looks like](https://github.com/sindresorhus/refined-github/blob/master/source/features/add-time-machine-links-to-comments.js) and [how it's loaded](https://github.com/sindresorhus/refined-github/blob/d7768508c3919558daa6b2ccc5a15aa73d081551/source/content.js#L176) (in this case it uses `observeEl` to automatically be run when new comments are loaded via AJAX)
- Each JavaScript feature lives in its own file under [`source/features`](https://github.com/sindresorhus/refined-github/tree/master/source/features) and it's imported in [`source/content.js`](https://github.com/sindresorhus/refined-github/blob/master/source/content.js).
- Some GitHub pages are loaded via AJAX/PJAX, so some features use the special `onAjaxedPages` loader (see it as a custom "on DOM ready").
- See what a _feature_ [looks like](https://github.com/sindresorhus/refined-github/blob/master/source/features/user-profile-follower-badge.js).
- If you're making changes to the README, try to match the style of the content that's already there and when in doubt, take a look at [our little style guide](https://github.com/sindresorhus/refined-github/issues/1139).

## `features.add`

The simplest usage of `feature.add` is the following. This will be run instantly on all page-loads (but not on ajax loads):

```js
import features from '../libs/features';

function init () {
console.log('✨');
}

features.add({
id: 'make-github-more-refined',
init
});
```

Here's an example using all of the possible `feature.add` options:


```js
import select from 'select-dom';
import features from '../libs/features';

function log() {
console.log('✨');
}
function init() {
select('.btn').addEventListener('click', log);
}
function deinit() {
select('.btn').removeEventListener('load', log);
}

features.add({
id: 'make-github-more-refined',
include: [
features.isUserProfile,
features.isOrganization
],
exclude: [
features.isOwnUserProfile
],
load: features.domReady, // Wait for dom-ready
// load: features.onAjaxedPages, // Or: Wait for dom-ready AND run on all ajaxed loads
// load: features.onNewComments, // Or: Wait for dom-ready AND run on all ajaxed loads AND watch for new comments
deinit, // Rarely needed
init
});
```


## Workflow

First clone:
Expand Down
34 changes: 22 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -20,12 +20,12 @@
"dom-chef": "^3.2.0",
"dom-loaded": "^1.0.1",
"element-ready": "^3.0.0",
"github-injection": "^1.0.1",
"github-reserved-names": "^1.1.4",
"intervalometer": "^1.0.4",
"linkify-issues": "^1.3.0",
"linkify-urls": "^2.2.0",
"onetime": "^2.0.1",
"p-is-promise": "^2.0.0",
"select-dom": "^4.1.3",
"shorten-repo-url": "^1.5.0",
"storm-textarea": "2.0.1",
Expand Down