Tutorial: Layout.applySnapshot

Layout.applySnapshot

Restores an application to a given snapshot.

Example


async function addViewToWindow(winId) {
    return await fin.Layout.createView({
        name: 'test_view_3',
        url: 'https://bing.com'
    }, winId);
}

async function createWindowWithTwoViews() {
    const identity = {
        name: 'test window',
        uuid: 'OpenFin POC'
    };

    await fin.Layout.createWindow({
        ...identity,
        layoutConfig: {
            content: [
                {
                    type: "stack",
                    content: [
                        {
                            type: "component",
                            componentName: "view",
                            componentState: {
                                name: "test_view_1",
                                url: "https://example.com"
                            }
                        },
                        {
                            type: "component",
                            componentName: "view",
                            componentState: {
                                name: "test_view_2",
                                url: "https://yahoo.com"
                            }
                        }
                    ]
                }
            ]
        }
    });

    return fin.Window.wrapSync(windowId);
}

let win = await createWindowWithTwoViews();
// ... you will now see a new window with two views in it

// we take a snapshot of the current state of the app, before changing it
const snapshotOfInitialAppState = await fin.Layout.getSnapshot();

// now let's change the state of the app:
await addViewToWindow(win.identity);
// ... the window now has three views in it

await fin.Layout.applySnapshot(snapshotOfInitialAppState);
// ... the window will revert to previous state, with just two views