Skip to content

Commit

Permalink
get rid of a bunch of cheating the typescript strict null checker in …
Browse files Browse the repository at this point in the history
…jupyter typescript
  • Loading branch information
williamstein committed Feb 20, 2019
1 parent 3e0de9f commit 98b993e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
33 changes: 18 additions & 15 deletions src/smc-webapp/jupyter/cell-list.tsx
Expand Up @@ -142,11 +142,14 @@ export class CellList extends Component<CellListProps> {
} // reset scroll request state

scroll_cell_list = (scroll: any) => {
const elt = $(this.cell_list_ref)!;
const elt = $(this.cell_list_ref);
if (elt == null) {
return;
}
if (elt.length > 0) {
let cur, top;
if (typeof scroll === "number") {
elt.scrollTop(elt.scrollTop()! + scroll);
elt.scrollTop(elt.scrollTop() + scroll);
return;
}

Expand All @@ -158,7 +161,7 @@ export class CellList extends Component<CellListProps> {
top = cur.position().top - elt.position().top;
if (top < PADDING) {
scroll = "cell top";
} else if (top > elt.height()! - PADDING) {
} else if (top > elt.height() - PADDING) {
scroll = "cell bottom";
} else {
return;
Expand All @@ -168,37 +171,37 @@ export class CellList extends Component<CellListProps> {
switch (scroll) {
case "list up":
// move scroll position of list up one page
return elt.scrollTop(elt.scrollTop()! - elt.height()! * 0.9);
return elt.scrollTop(elt.scrollTop() - elt.height() * 0.9);
case "list down":
// move scroll position of list up one page
return elt.scrollTop(elt.scrollTop()! + elt.height()! * 0.9);
return elt.scrollTop(elt.scrollTop() + elt.height() * 0.9);
case "cell top":
cur = elt.find(`#${this.props.cur_id}`)!;
if (cur.length > 0) {
cur = elt.find(`#${this.props.cur_id}`);
if (cur != null && cur.length > 0) {
return elt.scrollTop(
elt.scrollTop()! +
elt.scrollTop() +
(cur.position().top - elt.position().top) -
PADDING
);
}
break;
case "cell center":
cur = elt.find(`#${this.props.cur_id}`)!;
if (cur.length > 0) {
cur = elt.find(`#${this.props.cur_id}`);
if (cur != null && cur.length > 0) {
return elt.scrollTop(
elt.scrollTop()! +
(cur.position()!.top - elt.position()!.top) -
elt.height()! * 0.5
elt.scrollTop() +
(cur.position().top - elt.position().top) -
elt.height() * 0.5
);
}
break;
case "cell bottom":
cur = elt.find(`#${this.props.cur_id}`);
if (cur.length > 0) {
return elt.scrollTop(
elt.scrollTop()! +
elt.scrollTop() +
(cur.position().top - elt.position().top) -
elt.height()! * 0.9 +
elt.height() * 0.9 +
PADDING
);
}
Expand Down
16 changes: 10 additions & 6 deletions src/smc-webapp/jupyter/nbconvert.tsx
Expand Up @@ -40,9 +40,10 @@ class Error extends Component<ErrorProps> {

componentWillReceiveProps(nextProps) {
if (
// TODO: is nbconvert suppose to exist here?
!misc.is_string(this.props.nbconvert!.get("error")) &&
misc.is_string(nextProps.nbconvert!.get("error"))
this.props.nbconvert != null &&
!misc.is_string(this.props.nbconvert.get("error")) &&
nextProps.nbconvert != null &&
misc.is_string(nextProps.nbconvert.get("error"))
) {
setTimeout(() => this.scroll(), 10);
}
Expand Down Expand Up @@ -129,10 +130,10 @@ export class NBConvert extends Component<NBConvertProps> {
}

render_download() {
if (this.props.nbconvert!.get("error")) {
if (this.props.nbconvert == null || this.props.nbconvert.get("error") || this.props.nbconvert_dialog == null) {
return;
}
const to = this.props.nbconvert_dialog!.get("to");
const to = this.props.nbconvert_dialog.get("to");
const info = NAMES[to];
if (info == null) {
return;
Expand Down Expand Up @@ -275,7 +276,10 @@ export class NBConvert extends Component<NBConvertProps> {
}

args = () => {
return ["--to", this.props.nbconvert_dialog!.get("to")]; // TODO: is this.props.nbconvert_dialog defined?
if (this.props.nbconvert_dialog == null) {
return []; // broken case -- shouldn't happen
}
return ["--to", this.props.nbconvert_dialog.get("to")];
};

run = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/smc-webapp/jupyter/top-buttonbar.tsx
Expand Up @@ -194,7 +194,7 @@ export class TopButtonbar0 extends Component<TopButtonbarProps> {

render_select_cell_type() {
let cell_type: any;
if (this.props.sel_ids != null ? this.props.sel_ids!.size > 1 : false) {
if (this.props.sel_ids != null ? this.props.sel_ids.size > 1 : false) {
cell_type = "multi";
} else {
cell_type =
Expand Down
6 changes: 3 additions & 3 deletions src/smc-webapp/jupyter/uncommitted-changes.tsx
Expand Up @@ -16,7 +16,7 @@ const STYLE: React.CSSProperties = {

interface UncommittedChangesProps {
has_uncommitted_changes?: boolean;
delay_ms?: number; // assumed not to change, default 5000
delay_ms: number; // assumed not to change, default 5000
}

interface UncommittedChangesState {
Expand Down Expand Up @@ -54,7 +54,7 @@ export class UncommittedChanges extends Component<
this._last_change = new Date();
}
if (new_props.has_uncommitted_changes) {
setTimeout(this._check, this.props.delay_ms! + 10);
setTimeout(this._check, this.props.delay_ms + 10);
}
}
componentWillUnmount() {
Expand All @@ -63,7 +63,7 @@ export class UncommittedChanges extends Component<
componentDidMount() {
this._mounted = true;
this._last_change = new Date(); // from truly undefined to known
setTimeout(this._check, this.props.delay_ms! + 10);
setTimeout(this._check, this.props.delay_ms + 10);
}
render() {
if (!this.props.has_uncommitted_changes) {
Expand Down

0 comments on commit 98b993e

Please sign in to comment.