Skip to content

Commit

Permalink
BDE-226 bind dynamically methods in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
nxmatic committed Mar 14, 2024
1 parent 9adbedd commit 695612c
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 40 deletions.
7 changes: 5 additions & 2 deletions src/main/browser-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ class BrowserStore {
};

// Bind methods
this.get = this.get.bind(this);
this.set = this.set.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

get(input) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/connect-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ class ConnectLocator {
this.worker = worker;

// Bind methods
this.url = this.url.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

url(value) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/declarative-net-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class DeclarativeNetEngine {
this.flushed = this.flushed.bind(this);
this.pending = this.pending.bind(this);
this.reset = this.reset.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});

// Initialize the engine
this.reset();
Expand Down
10 changes: 5 additions & 5 deletions src/main/designer-live-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class DesignerLivePreview {
this.cleanupFunctions = [];

// Bind methods
this.addNewRedirectionsOf = this.addNewRedirectionsOf.bind(this);
this.disable = this.disable.bind(this);
this.enable = this.enable.bind(this);
this.toggle = this.toggle.bind(this);
this.isEnabled = this.isEnabled.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

pushRedirectionsOf(rootUrl, json) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/desktop-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class DesktopNotifier {
this.worker = worker;

// Bind methods
this.notify = this.notify.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

notify(id, options) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/document-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ class DocumentBrowser {
this.worker = worker;

// Bind methods
this.jsonOf = this.jsonOf.bind(this);
this.openDocument = this.openDocument.bind(this);
this.openDocFromId = this.openDocFromId.bind(this);
this.openDocFromPath = this.openDocFromPath.bind(this);
this.doOpenDoc = this.doOpenDoc.bind(this);
this.suggestDocument = this.suggestDocument.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

listenToChromeEvents() {
Expand Down
6 changes: 5 additions & 1 deletion src/main/json-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ class JsonHighlighter {
this._input = '';

// Bind methods
this.input = this.input.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

input(input) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/repository-indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class RepositoryIndexer {
this.worker = worker;

// Bind methods
this.withNuxeo = this.withNuxeo.bind(this);
this.reindex = this.reindex.bind(this);
this.reindexNXQL = this.reindexNXQL.bind(this);
this.reindexDocId = this.reindexDocId.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

withNuxeo() {
Expand Down
22 changes: 5 additions & 17 deletions src/main/server-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ class ServerConnector {
this.nuxeo = undefined;

// Bind methods
this.onNewServer = this.onNewServer.bind(this);
this.connect = this.connect.bind(this);
this.disconnect = this.disconnect.bind(this);
this.executeOperation = this.executeOperation.bind(this);
this.executeScript = this.executeScript.bind(this);
this.isConnected = this.isConnected.bind(this);
this.handleErrors = this.handleErrors.bind(this);
this.query = this.query.bind(this);
this.restart = this.restart.bind(this);
this.runtimeInfo = this.runtimeInfo.bind(this);
this.withNuxeo = this.withNuxeo.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});

// listeners
this.onInputChanged = null;
Expand Down Expand Up @@ -47,12 +41,6 @@ class ServerConnector {
this.rootUrl = rootUrl;
this.nuxeo = new Nuxeo({ baseURL: this.rootUrl });
this.nuxeo.login()
// .then(() => this.worker.browserStore
// .set({ serverInfo: { rootUrl, nuxeo: this.nuxeo } })
// .then((store) => {
// console.log(`stored ${JSON.stringify(store)}`);
// resolve();
// }))
.then(() => {
chrome.omnibox.onInputChanged.addListener(this.onInputChanged = this.suggestDocument);
})
Expand Down
9 changes: 9 additions & 0 deletions src/main/server-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
class ServerLocator {
constructor(worker) {
this.worker = worker;

// Bind methods
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});

// ...
this.nuxeoUrlOf = (tabInfo) => {
// eslint-disable-next-line operator-linebreak
// Regular expression pattern
Expand Down
8 changes: 6 additions & 2 deletions src/main/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class ServiceWorkerMessageHandler {
constructor(worker) {
this.worker = worker;

// binds methods to this
this.handle = this.handle.bind(this);
// Bind methods
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

handle(request, sender, sendResponse) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/studio-hot-reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class StudioHotReloader {
this.worker = worker;

// Bind methods
this.reload = this.reload.bind(this);
Object.getOwnPropertyNames(Object.getPrototypeOf(this))
.filter((prop) => typeof this[prop] === 'function' && prop !== 'constructor')
.forEach((method) => {
this[method] = this[method].bind(this);
});
}

dependenciesMismatch(info = []) {
Expand Down

0 comments on commit 695612c

Please sign in to comment.