Tutorial: interop.addContextHandler

interop.addContextHandler

Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler, it will receive all of its declared contexts.

Example

function handleIncomingContext(contextInfo) {
    const { type, id } = contextInfo;
    switch (type) {
        case 'instrument':
            handleInstrumentContext(contextInfo);
            break;
        case 'country':
            handleCountryContext(contextInfo);
            break;

        default:
            break;
    }
}


function handleInstrumentContext(contextInfo) {
    const { type, id } = contextInfo;
    console.log('contextInfo for instrument', contextInfo)
}

function handleCountryContext(contextInfo) {
    const { type, id } = contextInfo;
    console.log('contextInfo for country', contextInfo)
}

fin.me.interop.addContextHandler(handleIncomingContext);

We are also testing the ability to add a context handler for specific contexts. If you would like to use this, please make sure you add your context handlers at the top level of your application, on a page that does not navigate/reload/re-render, to avoid memory leaks.

Experimental Example

function handleInstrumentContext(contextInfo) {
    const { type, id } = contextInfo;
    console.log('contextInfo for instrument', contextInfo)
}

function handleCountryContext(contextInfo) {
    const { type, id } = contextInfo;
    console.log('contextInfo for country', contextInfo)
}


fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
fin.me.interop.addContextHandler(handleCountryContext, 'country')