Tutorial: customContext

customContext

Example

This Example shows a window sharing context to all it's views. By executing the code here in the correct context, the view will have global broadcastContext and addContextListener methods available. The window will synchronize context between views such that calling broadcastContext in any of the views will invoke any listeners added with addContextListener in all attached views.

In Window (frame)

const me = fin.Window.getCurrentSync();
me.on('options-changed', async (event) => {
    if (event.diff.customContext) {
        const myViews = await me.getCurrentViews();
        const customContext = event.diff.customContext.newVal;
        myViews.forEach(v => {
            v.updateOptions({customContext});
        });
    }
})

in View (content)

const me = fin.View.getCurrentSync();
const broadcastContext = async (customContext) => {
    const myWindow = await me.getCurrentWindow()
    await myWindow.updateOptions({customContext})
};
const addContextListener = async (listener) => {
    await me.on('options-changed', (event) => {
        if (event.diff.customContext) {
            listener(event.diff.customContext.newVal);
        }
    });
}