Skip to content

Commit feda228

Browse files
committed
fix(svelte): reuse original Framework7 instance
fixes #3993 fixes #3992
1 parent 91b94d9 commit feda228

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/svelte/shared/f7.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
/* eslint-disable import/no-mutable-exports */
22
// eslint-disable-next-line
3-
import Framework7 from 'framework7/lite';
43
import { extend, unsetRouterIds } from './utils.js';
54

65
let f7;
76
const theme = {};
87

9-
// eslint-disable-next-line
10-
if (!Framework7.__app__) {
11-
// eslint-disable-next-line
12-
Framework7.__app__ = {
13-
f7: undefined,
14-
f7events: undefined,
15-
theme: {},
16-
f7routers: {
17-
views: [],
18-
tabs: [],
19-
modals: null,
20-
},
21-
};
8+
/* eslint-disable no-restricted-globals */
9+
const app =
10+
typeof window !== 'undefined' && window.Framework7ComponentsApp
11+
? window.Framework7ComponentsApp
12+
: {
13+
Framework7: undefined,
14+
f7: undefined,
15+
f7events: undefined,
16+
theme: {},
17+
f7routers: {
18+
views: [],
19+
tabs: [],
20+
modals: null,
21+
},
22+
};
23+
if (typeof window !== 'undefined') {
24+
window.Framework7ComponentsApp = app;
2225
}
23-
24-
const { __app__: app } = Framework7;
26+
/* eslint-enable no-restricted-globals */
2527

2628
app.setInstance = (instance) => {
2729
f7 = instance;
@@ -51,7 +53,7 @@ const cleanup = () => {
5153
};
5254

5355
const f7initEvents = () => {
54-
app.f7events = new Framework7.Events();
56+
app.f7events = new app.Framework7.Events();
5557
};
5658

5759
const f7init = (rootEl, params = {}, init = true) => {
@@ -63,7 +65,7 @@ const f7init = (rootEl, params = {}, init = true) => {
6365
if (!f7Params.routes) f7Params.routes = [];
6466

6567
if (f7Params.userAgent && (f7Params.theme === 'auto' || !f7Params.theme)) {
66-
const device = Framework7.getDevice({ userAgent: f7Params.userAgent }, true);
68+
const device = app.Framework7.getDevice({ userAgent: f7Params.userAgent }, true);
6769
app.theme.ios = !!device.ios;
6870
app.theme.aurora = device.desktop && device.electron;
6971
app.theme.md = !app.theme.ios && !app.theme.aurora;
@@ -74,7 +76,7 @@ const f7init = (rootEl, params = {}, init = true) => {
7476
// eslint-disable-next-line
7577
if (typeof window === 'undefined') cleanup();
7678

77-
const instance = new Framework7(f7Params);
79+
const instance = new app.Framework7(f7Params);
7880
app.f7 = instance;
7981
f7 = instance;
8082
app.setInstance(instance);

src/svelte/shared/plugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// eslint-disable-next-line
2-
import Framework7 from 'framework7/lite';
32
import componentsRouter from './components-router.js';
43
import { f7ready, theme, app, f7initEvents, setTheme } from './f7.js';
54

65
const Framework7Svelte = {
76
name: 'sveltePlugin',
87
installed: false,
98
install(params = {}) {
9+
const Framework7 = this;
10+
app.Framework7 = Framework7;
11+
1012
if (Framework7Svelte.installed) return;
1113
Framework7Svelte.installed = true;
1214

0 commit comments

Comments
 (0)