-
Notifications
You must be signed in to change notification settings - Fork 3
notebook cleanups #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
ry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Let me know when I should review again.
src/types.ts
Outdated
|
|
||
| /** | ||
| * This file contains common types we use across the project. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 1 line instead of 3
// Common types used across the project.
src/snippet.tsx
Outdated
| */ | ||
|
|
||
| /** | ||
| * Snippet is a cell showsing preview of a notebook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "showsing"
Also - this could use a better name - like "NotebookPreview" or something.
src/list.tsx
Outdated
| onClick?: (nbId: string) => void; | ||
| } | ||
|
|
||
| export class List extends Component<ListProps, {}> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call it NotebookList?
src/profile.tsx
Outdated
| const doc = this.props.notebooks[0].doc; | ||
| // TODO Profile is reusing the most-recent css class, because it's a very | ||
| // similar layout. The CSS class should be renamed something appropriate | ||
| // for both of them, maybe nb-listing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good TODO. Let's try to move towards consistency between the CSS classes and the component names.
55feba0 to
b3ff2fe
Compare
|
Waiting for preactjs/preact-router#281 to be resolved... |
src/components/logo.tsx
Outdated
| limitations under the License. | ||
| */ | ||
|
|
||
| // tslint:disable:variable-name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to use tslint:disable-next-line:variable-name and move it where it's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/components/index.tsx
Outdated
|
|
||
| export const PropelIndex = props => { | ||
| let md = readFileSync(__dirname + "/../README.md", "utf8"); | ||
| console.log(__dirname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover debug statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thank you Bert
1a7b490 to
ab76944
Compare
|
64ecd69 to
2ea7e8b
Compare
|
@ry @piscisaureus PTAL |
|
@qti3e This branch needs to be rebased |
src/app.tsx
Outdated
| error: string; | ||
| } | ||
|
|
||
| function bind(C, bindProps: BindProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a common react pattern? Can you add docs or a link to a description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - Please add that link to the source code
| this.loadData(); | ||
| const { data, error } = this.state; | ||
| if (error) return <ErrorPage message={error} />; | ||
| if (!data) return <Loading />; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| <div class="notebook"> | ||
| <GlobalHeader subtitle="Notebook" subtitleLink="/"> | ||
| <UserMenu userInfo={userInfo} /> | ||
| </GlobalHeader> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that we have a single reference to the global header now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: )
|
@qti3e https://gist.github.com/fffc74c4dbbf65e275d3093d043ab8fc <-- conflicting changes |
src/components/common.tsx
Outdated
| // Careful, S3 is finicky about what URLs it serves. So | ||
| // /notebook?nbId=blah will get redirect to /notebook/ | ||
| // because it is a directory with an index.html in it. | ||
| const u = window.location.origin + "/notebook/?nbId=" + nbId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be rebased.
src/app.tsx
Outdated
| created: new Date(), | ||
| owner: { | ||
| displayName: "Anonymous", | ||
| photoURL: "/static/img/anon_profile.png?", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be rebased
| "preserveConstEnums": true, | ||
| "pretty": true, | ||
| "sourceMap": true, | ||
| "allowSyntheticDefaultImports": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import pathToRegexp from "path-to-regexp";the default export of path-to-regexp is a function and we need to use that, on the other hand,when allowSyntheticDefaultImports is disabled, ts will throw an error:
"path-to-regexp" has no default export.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try import * as pathToRegExp from "path-to-regexp" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piscisaureus yeah, but it would throw a run-time error (see my comment below)
|
@qti3e I rebased this branch again. |
|
@piscisaureus @ry I made some changes to the router and implemented a new component ( |
src/app.tsx
Outdated
| import { Recent } from "./components/recent"; | ||
|
|
||
| interface BindProps { | ||
| [key: string]: (props: any) => Promise<any>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I have with this is that it breaks the type-checker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can somewhat bring back type safety by applying the following patch:
diff --git a/src/app.tsx b/src/app.tsx
index 85d3297..318aa28 100644
--- a/src/app.tsx
+++ b/src/app.tsx
@@ -27,15 +27,26 @@ import { Notebook } from "./components/notebook";
import { Profile } from "./components/profile";
import { Recent } from "./components/recent";
-interface BindProps {
- [key: string]: (props: any) => Promise<any>;
+type Partial<T> = {
+ [K in keyof T]?: T[K];
+};
+
+type BindProps<P> = {
+ readonly [K in keyof P]?: (props: P) => Promise<P[K]>;
+};
+
+interface BindStateNormal<P> {
+ data: { [K in keyof P]: P[K] };
+ error: null;
}
-interface BindState {
- data: { [key: string]: string };
+interface BindStateError {
+ data: null;
error: string;
}
+type BindState<P> = BindStateNormal<P> | BindStateError;
+
/**
* This react HOC can be used to bind result of some async
* methods to props of the given component (C).
@@ -48,8 +59,8 @@ interface BindState {
* }
* });
*/
-function bind(C, bindProps: BindProps) {
- return class extends Component<any, BindState> {
+function bind<P>(C, bindProps: BindProps<P>) {
+ return class extends Component<Partial<P>, BindState<P>> {
state = { data: null, error: null };
prevMatches = null;
componentRef;
@@ -61,7 +72,7 @@ function bind(C, bindProps: BindProps) {
async loadData() {
if (equal(this.props.matches, this.prevMatches)) return;
this.prevMatches = this.props.matches;
- const data = {};
+ const data: any = {};
for (const key in bindProps) {
if (!bindProps[key]) continue;
try {However typescript complains about the fact that the onReady and matches properties aren't defined anywhere, and it looks like it's right about that...
Same for the path attribute used when instantiating the page components (<RecentPage path="/" userInfo={userInfo} /> etc.)
I am not afraid of some black magic voodoo code, but it has to be correct before I am going to accept it.
On an aside, did you consider simply using getters/setters? Maybe that's a bit easier to reason about.
7332616 to
c519b5c
Compare
|
@piscisaureus I dropped 1e67a10 due to: |
|
@piscisaureus PTAL |
b1c80a2 to
2d5018d
Compare
ry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - cursory review - I defer to @piscisaureus for the final approval
| this.loadData(); | ||
| const { data, error } = this.state; | ||
| if (error) return <ErrorPage message={error} />; | ||
| if (!data) return <Loading />; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/app.tsx
Outdated
| } | ||
|
|
||
| // An anonymous notebook doc for when users aren't logged in | ||
| const anonDoc = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be exported so it could be used in tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| await flush(); | ||
| assertEqual(path(), "/page/345"); | ||
| assertEqual(activePage(), "p3"); | ||
| assertEqual(matchedProps.get("p3").v, "345"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test!
| message: string; | ||
| } | ||
|
|
||
| export function ErrorPage(props: ErrorPageProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This could be done in one line...
function ErrorPage(props: { header?: string, message: string }): JSX.Element {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max-line-length: Exceeds maximum line length of 80
|
@piscisaureus any comments? : ) |
| } | ||
|
|
||
| render() { | ||
| this.loadData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but this just isn't right.
Since loadData() is async, it causes the following loop:
tick 1: render() -> starts loadData()
tick 2: loadData() calls setState() -> render() gets called -> starts another loadData().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piscisaureus loadData only calls setState when props has been changed
+ if (equal(this.props.matches, this.prevMatches)) return;
+ this.prevMatches = this.props.matches;| } | ||
| }); | ||
|
|
||
| export const HomePage = bind(Home as any, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as any is inappropriate here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's because Home is a functional component... I'll try again to remove this any
and other unused codes
and some fixes in components
TODO:
../srcfrom import statementsSnippetNotebookPreviewcommon.tsxdown to small files and move notebook components to./componentspreact-routerand change routes