Skip to content

Commit 47e4077

Browse files
committed
Bind app methods to app instance
1 parent e4dd917 commit 47e4077

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/core/components/app/app-class.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Framework7 extends Framework7Class {
3030
// Extend defaults with modules params
3131
app.useModulesParams(defaults);
3232

33-
3433
// Extend defaults with passed params
3534
app.params = Utils.extend(defaults, params);
3635

@@ -80,13 +79,12 @@ class Framework7 extends Framework7Class {
8079
app.init();
8180
}
8281
}
83-
8482
// Return app instance
8583
return app;
8684
}
8785
init() {
8886
const app = this;
89-
if (app.initialized) return;
87+
if (app.initialized) return app;
9088

9189
app.root.addClass('framework7-initializing');
9290

@@ -111,7 +109,13 @@ class Framework7 extends Framework7Class {
111109
// Methods
112110
app.methods = {};
113111
if (app.params.methods) {
114-
Utils.extend(app.methods, app.params.methods);
112+
Object.keys(app.params.methods).forEach((methodName) => {
113+
if (typeof app.params.methods[methodName] === 'function') {
114+
app.methods[methodName] = app.params.methods[methodName].bind(app);
115+
} else {
116+
app.methods[methodName] = app.params.methods[methodName];
117+
}
118+
});
115119
}
116120
// Init class
117121
Utils.nextFrame(() => {
@@ -120,6 +124,8 @@ class Framework7 extends Framework7Class {
120124
// Emit, init other modules
121125
app.initialized = true;
122126
app.emit('init');
127+
128+
return app;
123129
}
124130
// eslint-disable-next-line
125131
get $() {

0 commit comments

Comments
 (0)