Skip to content

Commit d4a2620

Browse files
committed
Change handleEvent option to eventHandler.
1 parent d1dbda1 commit d4a2620

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Support test environment in EARL output.
66
- Support benchmark output in EARL output.
77
- Benchmark comparison tool.
8-
- Event handler option "`handleEvent`" to allow custom handling of warnings and
8+
- Event handler option `"eventHandler"` to allow custom handling of warnings and
99
potentially other events in the future. Handles event replay for cached
1010
contexts.
1111

lib/context.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ api.process = async ({
6767

6868
// event handler for capturing events to replay when using a cached context
6969
const events = [];
70-
const handleEvent = [
70+
const eventHandler = [
7171
({event, next}) => {
7272
events.push(event);
7373
next();
7474
}
7575
];
7676
// chain to original handler
77-
if(options.handleEvent) {
78-
handleEvent.push(options.handleEvent);
77+
if(options.eventHandler) {
78+
eventHandler.push(options.eventHandler);
7979
}
8080
// store original options to use when replaying events
8181
const originalOptions = options;
8282
// shallow clone options with custom event handler
83-
options = Object.assign({}, options, {handleEvent});
83+
options = Object.assign({}, options, {eventHandler});
8484

8585
// resolve contexts
8686
const resolved = await options.contextResolver.resolve({

lib/events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = api;
1919
/**
2020
* Handle an event.
2121
*
22-
* Top level APIs have a common 'handleEvent' option. This option can be a
22+
* Top level APIs have a common 'eventHandler' option. This option can be a
2323
* function, array of functions, object mapping event.code to functions (with a
2424
* default to call next()), or any combination of such handlers. Handlers will
2525
* be called with an object with an 'event' entry and a 'next' function. Custom
@@ -34,14 +34,14 @@ module.exports = api;
3434
* {string} level - severity level, one of: ['warning']
3535
* {string} message - human readable message
3636
* {object} details - event specific details
37-
* @param {object} options - original API options
37+
* @param {object} options - processing options
3838
*/
3939
api.handleEvent = ({
4040
event,
4141
options
4242
}) => {
4343
const handlers = [].concat(
44-
options.handleEvent ? _asArray(options.handleEvent) : [],
44+
options.eventHandler ? _asArray(options.eventHandler) : [],
4545
_defaultHandler
4646
);
4747
_handle({event, handlers});

lib/jsonld.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const _resolvedContextCache = new LRU({max: RESOLVED_CONTEXT_CACHE_MAX_SIZE});
119119
* unmappable values (or to throw an error when they are detected);
120120
* if this function returns `undefined` then the default behavior
121121
* will be used.
122-
* [handleEvent] handler for events such as warnings.
122+
* [eventHandler] handler for events.
123123
* [contextResolver] internal use only.
124124
*
125125
* @return a Promise that resolves to the compacted output.
@@ -258,7 +258,7 @@ jsonld.compact = async function(input, ctx, options) {
258258
* unmappable values (or to throw an error when they are detected);
259259
* if this function returns `undefined` then the default behavior
260260
* will be used.
261-
* [handleEvent] handler for events such as warnings.
261+
* [eventHandler] handler for events.
262262
* [contextResolver] internal use only.
263263
*
264264
* @return a Promise that resolves to the expanded output.
@@ -356,7 +356,7 @@ jsonld.expand = async function(input, options) {
356356
* [base] the base IRI to use.
357357
* [expandContext] a context to expand with.
358358
* [documentLoader(url, options)] the document loader.
359-
* [handleEvent] handler for events such as warnings.
359+
* [eventHandler] handler for events.
360360
* [contextResolver] internal use only.
361361
*
362362
* @return a Promise that resolves to the flattened output.
@@ -412,7 +412,7 @@ jsonld.flatten = async function(input, ctx, options) {
412412
* [requireAll] default @requireAll flag (default: true).
413413
* [omitDefault] default @omitDefault flag (default: false).
414414
* [documentLoader(url, options)] the document loader.
415-
* [handleEvent] handler for events such as warnings.
415+
* [eventHandler] handler for events.
416416
* [contextResolver] internal use only.
417417
*
418418
* @return a Promise that resolves to the framed output.
@@ -511,7 +511,7 @@ jsonld.frame = async function(input, frame, options) {
511511
* [base] the base IRI to use.
512512
* [expandContext] a context to expand with.
513513
* [documentLoader(url, options)] the document loader.
514-
* [handleEvent] handler for events such as warnings.
514+
* [eventHandler] handler for events.
515515
* [contextResolver] internal use only.
516516
*
517517
* @return a Promise that resolves to the linked output.
@@ -547,7 +547,7 @@ jsonld.link = async function(input, ctx, options) {
547547
* 'application/n-quads' for N-Quads.
548548
* [documentLoader(url, options)] the document loader.
549549
* [useNative] true to use a native canonize algorithm
550-
* [handleEvent] handler for events such as warnings.
550+
* [eventHandler] handler for events.
551551
* [contextResolver] internal use only.
552552
*
553553
* @return a Promise that resolves to the normalized output.
@@ -604,7 +604,7 @@ jsonld.normalize = jsonld.canonize = async function(input, options) {
604604
* (boolean, integer, double), false not to (default: false).
605605
* [rdfDirection] 'i18n-datatype' to support RDF transformation of
606606
* @direction (default: null).
607-
* [handleEvent] handler for events such as warnings.
607+
* [eventHandler] handler for events.
608608
*
609609
* @return a Promise that resolves to the JSON-LD document.
610610
*/
@@ -654,7 +654,7 @@ jsonld.fromRDF = async function(dataset, options) {
654654
* [produceGeneralizedRdf] true to output generalized RDF, false
655655
* to produce only standard RDF (default: false).
656656
* [documentLoader(url, options)] the document loader.
657-
* [handleEvent] handler for events such as warnings.
657+
* [eventHandler] handler for events.
658658
* [contextResolver] internal use only.
659659
*
660660
* @return a Promise that resolves to the RDF dataset.
@@ -708,7 +708,7 @@ jsonld.toRDF = async function(input, options) {
708708
* [expandContext] a context to expand with.
709709
* [issuer] a jsonld.IdentifierIssuer to use to label blank nodes.
710710
* [documentLoader(url, options)] the document loader.
711-
* [handleEvent] handler for events such as warnings.
711+
* [eventHandler] handler for events.
712712
* [contextResolver] internal use only.
713713
*
714714
* @return a Promise that resolves to the merged node map.
@@ -748,7 +748,7 @@ jsonld.createNodeMap = async function(input, options) {
748748
* new properties where a node is in the `object` position
749749
* (default: true).
750750
* [documentLoader(url, options)] the document loader.
751-
* [handleEvent] handler for events such as warnings.
751+
* [eventHandler] handler for events.
752752
* [contextResolver] internal use only.
753753
*
754754
* @return a Promise that resolves to the merged output.
@@ -911,7 +911,7 @@ jsonld.get = async function(url, options) {
911911
* @param localCtx the local context to process.
912912
* @param [options] the options to use:
913913
* [documentLoader(url, options)] the document loader.
914-
* [handleEvent] handler for events such as warnings.
914+
* [eventHandler] handler for events.
915915
* [contextResolver] internal use only.
916916
*
917917
* @return a Promise that resolves to the new active context.

tests/misc.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ describe('events', () => {
12791279

12801280
let handled = false;
12811281
const e = await jsonld.expand(d, {
1282-
handleEvent: ({event, next}) => {
1282+
eventHandler: ({event, next}) => {
12831283
if(event.code === 'invalid reserved term') {
12841284
handled = true;
12851285
} else {
@@ -1304,15 +1304,15 @@ describe('events', () => {
13041304
let handled0 = false;
13051305
let handled1 = false;
13061306
const e0 = await jsonld.expand(d, {
1307-
handleEvent: {
1307+
eventHandler: {
13081308
'invalid reserved term': () => {
13091309
handled0 = true;
13101310
}
13111311
}
13121312
});
13131313
// FIXME: ensure cache is being used
13141314
const e1 = await jsonld.expand(d, {
1315-
handleEvent: {
1315+
eventHandler: {
13161316
'invalid reserved term': () => {
13171317
handled1 = true;
13181318
}
@@ -1338,7 +1338,7 @@ describe('events', () => {
13381338
let ranHandler1 = false;
13391339
let handled = false;
13401340
const e = await jsonld.expand(d, {
1341-
handleEvent: [
1341+
eventHandler: [
13421342
({next}) => {
13431343
ranHandler0 = true;
13441344
// skip to next handler
@@ -1372,7 +1372,7 @@ describe('events', () => {
13721372

13731373
let handled = false;
13741374
const e = await jsonld.expand(d, {
1375-
handleEvent: {
1375+
eventHandler: {
13761376
'invalid reserved term': ({event}) => {
13771377
assert.equal(event.details.term, '@RESERVED');
13781378
handled = true;
@@ -1399,7 +1399,7 @@ describe('events', () => {
13991399
let ranHandler3 = false;
14001400
let handled = false;
14011401
const e = await jsonld.expand(d, {
1402-
handleEvent: [
1402+
eventHandler: [
14031403
({next}) => {
14041404
ranHandler0 = true;
14051405
next();
@@ -1463,7 +1463,7 @@ describe('events', () => {
14631463
let handledReservedValue = false;
14641464
let handledLanguage = false;
14651465
const e = await jsonld.expand(d, {
1466-
handleEvent: {
1466+
eventHandler: {
14671467
'invalid reserved term': () => {
14681468
handledReservedTerm = true;
14691469
},
@@ -1528,7 +1528,7 @@ describe('events', () => {
15281528
let handledLanguage2 = false;
15291529
const e2 = await jsonld.fromRDF(d2, {
15301530
rdfDirection: 'i18n-datatype',
1531-
handleEvent: {
1531+
eventHandler: {
15321532
'invalid @language value': () => {
15331533
handledLanguage2 = true;
15341534
}

0 commit comments

Comments
 (0)