Как разные виджеты / windows общаются в openfin - PullRequest
0 голосов
/ 16 января 2020

Как и в openfin, у нас могут быть отдельные виджеты / windows, открытые отдельно, как они общаются друг с другом, много искали, ничего не смогли найти по этому поводу, пожалуйста, помогите.

1 Ответ

0 голосов
/ 19 апреля 2020

Вы можете поделиться контекстом из главного окна для всех его родительских представлений, используя customContext

В окне (фрейм)

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 });
        });
    }
})

в Просмотр (содержание)

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);
        }
    });
}

Ссылки - https://cdn.openfin.co/docs/javascript/stable/tutorial-customContext.html

...