Skip to content

Commit 3343858

Browse files
committed
Change handleEvent option to eventHandler.
1 parent d78747d commit 3343858

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
@@ -28,7 +28,7 @@
2828
- Support for expansion and compaction of values container `"@direction"`.
2929
- Support for RDF transformation of `@direction` when `rdfDirection` is
3030
'i18n-datatype'.
31-
- Event handler option "`handleEvent`" to allow custom handling of warnings and
31+
- Event handler option `"eventHandler"` to allow custom handling of warnings and
3232
potentially other events in the future. Handles event replay for cached
3333
contexts.
3434

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
@@ -123,7 +123,7 @@ const _resolvedContextCache = new LRU({max: RESOLVED_CONTEXT_CACHE_MAX_SIZE});
123123
* unmappable values (or to throw an error when they are detected);
124124
* if this function returns `undefined` then the default behavior
125125
* will be used.
126-
* [handleEvent] handler for events such as warnings.
126+
* [eventHandler] handler for events.
127127
* [contextResolver] internal use only.
128128
*
129129
* @return a Promise that resolves to the compacted output.
@@ -272,7 +272,7 @@ jsonld.compact = async function(input, ctx, options) {
272272
* unmappable values (or to throw an error when they are detected);
273273
* if this function returns `undefined` then the default behavior
274274
* will be used.
275-
* [handleEvent] handler for events such as warnings.
275+
* [eventHandler] handler for events.
276276
* [contextResolver] internal use only.
277277
*
278278
* @return a Promise that resolves to the expanded output.
@@ -370,7 +370,7 @@ jsonld.expand = async function(input, options) {
370370
* [base] the base IRI to use.
371371
* [expandContext] a context to expand with.
372372
* [documentLoader(url, options)] the document loader.
373-
* [handleEvent] handler for events such as warnings.
373+
* [eventHandler] handler for events.
374374
* [contextResolver] internal use only.
375375
*
376376
* @return a Promise that resolves to the flattened output.
@@ -426,7 +426,7 @@ jsonld.flatten = async function(input, ctx, options) {
426426
* [requireAll] default @requireAll flag (default: true).
427427
* [omitDefault] default @omitDefault flag (default: false).
428428
* [documentLoader(url, options)] the document loader.
429-
* [handleEvent] handler for events such as warnings.
429+
* [eventHandler] handler for events.
430430
* [contextResolver] internal use only.
431431
*
432432
* @return a Promise that resolves to the framed output.
@@ -509,7 +509,7 @@ jsonld.frame = async function(input, frame, options) {
509509
* [base] the base IRI to use.
510510
* [expandContext] a context to expand with.
511511
* [documentLoader(url, options)] the document loader.
512-
* [handleEvent] handler for events such as warnings.
512+
* [eventHandler] handler for events.
513513
* [contextResolver] internal use only.
514514
*
515515
* @return a Promise that resolves to the linked output.
@@ -545,7 +545,7 @@ jsonld.link = async function(input, ctx, options) {
545545
* 'application/n-quads' for N-Quads.
546546
* [documentLoader(url, options)] the document loader.
547547
* [useNative] true to use a native canonize algorithm
548-
* [handleEvent] handler for events such as warnings.
548+
* [eventHandler] handler for events.
549549
* [contextResolver] internal use only.
550550
*
551551
* @return a Promise that resolves to the normalized output.
@@ -602,7 +602,7 @@ jsonld.normalize = jsonld.canonize = async function(input, options) {
602602
* (boolean, integer, double), false not to (default: false).
603603
* [rdfDirection] 'i18n-datatype' to support RDF transformation of
604604
* @direction (default: null).
605-
* [handleEvent] handler for events such as warnings.
605+
* [eventHandler] handler for events.
606606
*
607607
* @return a Promise that resolves to the JSON-LD document.
608608
*/
@@ -652,7 +652,7 @@ jsonld.fromRDF = async function(dataset, options) {
652652
* [produceGeneralizedRdf] true to output generalized RDF, false
653653
* to produce only standard RDF (default: false).
654654
* [documentLoader(url, options)] the document loader.
655-
* [handleEvent] handler for events such as warnings.
655+
* [eventHandler] handler for events.
656656
* [contextResolver] internal use only.
657657
*
658658
* @return a Promise that resolves to the RDF dataset.
@@ -706,7 +706,7 @@ jsonld.toRDF = async function(input, options) {
706706
* [expandContext] a context to expand with.
707707
* [issuer] a jsonld.IdentifierIssuer to use to label blank nodes.
708708
* [documentLoader(url, options)] the document loader.
709-
* [handleEvent] handler for events such as warnings.
709+
* [eventHandler] handler for events.
710710
* [contextResolver] internal use only.
711711
*
712712
* @return a Promise that resolves to the merged node map.
@@ -746,7 +746,7 @@ jsonld.createNodeMap = async function(input, options) {
746746
* new properties where a node is in the `object` position
747747
* (default: true).
748748
* [documentLoader(url, options)] the document loader.
749-
* [handleEvent] handler for events such as warnings.
749+
* [eventHandler] handler for events.
750750
* [contextResolver] internal use only.
751751
*
752752
* @return a Promise that resolves to the merged output.
@@ -909,7 +909,7 @@ jsonld.get = async function(url, options) {
909909
* @param localCtx the local context to process.
910910
* @param [options] the options to use:
911911
* [documentLoader(url, options)] the document loader.
912-
* [handleEvent] handler for events such as warnings.
912+
* [eventHandler] handler for events.
913913
* [contextResolver] internal use only.
914914
*
915915
* @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
@@ -498,7 +498,7 @@ describe('events', () => {
498498

499499
let handled = false;
500500
const e = await jsonld.expand(d, {
501-
handleEvent: ({event, next}) => {
501+
eventHandler: ({event, next}) => {
502502
if(event.code === 'invalid reserved term') {
503503
handled = true;
504504
} else {
@@ -523,15 +523,15 @@ describe('events', () => {
523523
let handled0 = false;
524524
let handled1 = false;
525525
const e0 = await jsonld.expand(d, {
526-
handleEvent: {
526+
eventHandler: {
527527
'invalid reserved term': () => {
528528
handled0 = true;
529529
}
530530
}
531531
});
532532
// FIXME: ensure cache is being used
533533
const e1 = await jsonld.expand(d, {
534-
handleEvent: {
534+
eventHandler: {
535535
'invalid reserved term': () => {
536536
handled1 = true;
537537
}
@@ -557,7 +557,7 @@ describe('events', () => {
557557
let ranHandler1 = false;
558558
let handled = false;
559559
const e = await jsonld.expand(d, {
560-
handleEvent: [
560+
eventHandler: [
561561
({next}) => {
562562
ranHandler0 = true;
563563
// skip to next handler
@@ -591,7 +591,7 @@ describe('events', () => {
591591

592592
let handled = false;
593593
const e = await jsonld.expand(d, {
594-
handleEvent: {
594+
eventHandler: {
595595
'invalid reserved term': ({event}) => {
596596
assert.equal(event.details.term, '@RESERVED');
597597
handled = true;
@@ -618,7 +618,7 @@ describe('events', () => {
618618
let ranHandler3 = false;
619619
let handled = false;
620620
const e = await jsonld.expand(d, {
621-
handleEvent: [
621+
eventHandler: [
622622
({next}) => {
623623
ranHandler0 = true;
624624
next();
@@ -682,7 +682,7 @@ describe('events', () => {
682682
let handledReservedValue = false;
683683
let handledLanguage = false;
684684
const e = await jsonld.expand(d, {
685-
handleEvent: {
685+
eventHandler: {
686686
'invalid reserved term': () => {
687687
handledReservedTerm = true;
688688
},
@@ -747,7 +747,7 @@ describe('events', () => {
747747
let handledLanguage2 = false;
748748
const e2 = await jsonld.fromRDF(d2, {
749749
rdfDirection: 'i18n-datatype',
750-
handleEvent: {
750+
eventHandler: {
751751
'invalid @language value': () => {
752752
handledLanguage2 = true;
753753
}

0 commit comments

Comments
 (0)