Skip to content

Commit a78f4e5

Browse files
committed
Refactor if statement and isExpandable function
1 parent 08fbecb commit a78f4e5

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

src/components/sharedNotebookRenderStrategy.tsx

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -115,37 +115,37 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
115115
}
116116

117117
private onExpand() {
118-
if (this.isExpandable()) {
119-
if (!this.notebook.apiProperties && !this.notebook.startedLoading && this.globals.oneNoteDataProvider) {
120-
// This notebook was made known to us by GetRecentNotebooks, but we haven't
121-
// fetched any metadata or children info
122-
this.notebook.startedLoading = true;
123-
const depth = this.globals.notebookExpandDepth || 5;
124-
125-
this.globals.oneNoteDataProvider.getSpNotebookProperties(this.notebook, depth, true).then((apiProperties) => {
126-
if (!apiProperties) {
127-
this.notebook.apiHttpErrorCode = 404;
128-
return;
129-
}
130-
131-
this.notebook.apiProperties = apiProperties;
132-
133-
if (this.globals.notebookListUpdater) {
134-
this.globals.notebookListUpdater.updateNotebookList([this.notebook]);
135-
}
136-
}).catch((xhrs: XMLHttpRequest[]) => {
137-
let max = 0;
138-
for (let i = 0; i < xhrs.length; i++) {
139-
max = Math.max(xhrs[i].status, max);
140-
}
141-
this.notebook.apiHttpErrorCode = max;
142-
}).then(() => {
143-
let { onSharedNotebookInfoReturned } = this.globals.callbacks;
144-
if (!!onSharedNotebookInfoReturned) {
145-
onSharedNotebookInfoReturned(this.notebook);
146-
}
147-
});
148-
}
118+
// Check if the picker is expandable
119+
if ((this.globals.callbacks.onSectionSelected || !!this.globals.callbacks.onPageSelected) &&
120+
!this.notebook.apiProperties && !this.notebook.startedLoading && this.globals.oneNoteDataProvider) {
121+
// This notebook was made known to us by GetRecentNotebooks, but we haven't
122+
// fetched any metadata or children info
123+
this.notebook.startedLoading = true;
124+
const depth = this.globals.notebookExpandDepth || 5;
125+
126+
this.globals.oneNoteDataProvider.getSpNotebookProperties(this.notebook, depth, true).then((apiProperties) => {
127+
if (!apiProperties) {
128+
this.notebook.apiHttpErrorCode = 404;
129+
return;
130+
}
131+
132+
this.notebook.apiProperties = apiProperties;
133+
134+
if (this.globals.notebookListUpdater) {
135+
this.globals.notebookListUpdater.updateNotebookList([this.notebook]);
136+
}
137+
}).catch((xhrs: XMLHttpRequest[]) => {
138+
let max = 0;
139+
for (let i = 0; i < xhrs.length; i++) {
140+
max = Math.max(xhrs[i].status, max);
141+
}
142+
this.notebook.apiHttpErrorCode = max;
143+
}).then(() => {
144+
let { onSharedNotebookInfoReturned } = this.globals.callbacks;
145+
if (!!onSharedNotebookInfoReturned) {
146+
onSharedNotebookInfoReturned(this.notebook);
147+
}
148+
});
149149
}
150150
}
151151

@@ -154,8 +154,4 @@ export class SharedNotebookRenderStrategy implements ExpandableNodeRenderStrateg
154154
let split = url.split('/');
155155
return split.slice(3, -1).map(decodeURIComponent).join('/');
156156
}
157-
158-
private isExpandable(): boolean {
159-
return !!this.globals.callbacks.onSectionSelected || !!this.globals.callbacks.onPageSelected;
160-
}
161157
}

0 commit comments

Comments
 (0)