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

Expose the AuditQueue instance, add the isRunning property to it #29

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ When adding agnostic-axe to your project, be sure to only import it in your deve
Accepts one parameter:

- `violationsCallback` (required). A function that is invoked with an array of violations, as reported by [axe-core](https://github.com/dequelabs/axe-core). To log violations to the console, simply pass the `logViolations` function exported by this module.
- `auditQueueCallback` (optional). A function that is invoked with an instance of `AuditQueue` to be able to access its state (i.e., the `isRunning` property).

### AxeObserver.observe

Expand Down
3 changes: 3 additions & 0 deletions src/AuditQueue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ export default class AuditQueue {
}
})
}
get isRunning() {
return this._isRunning
}
}
6 changes: 5 additions & 1 deletion src/AxeObserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SharedAuditQueue = new AuditQueue()
// The AxeObserver class takes a violationsCallback, which is invoked with an
// array of observed violations.
export default class AxeObserver {
constructor(violationsCallback) {
constructor(violationsCallback, auditQueueCallback) {
if (typeof violationsCallback !== 'function') {
throw new Error(
'The AxeObserver constructor requires a violationsCallback'
Expand All @@ -42,6 +42,10 @@ export default class AxeObserver {
this._auditNode(mutationRecord.target)
})
})

if (auditQueueCallback) {
auditQueueCallback(SharedAuditQueue)
}
}
observe(targetNode) {
if (!targetNode) {
Expand Down