Conversation
ry
left a comment
There was a problem hiding this comment.
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.
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.
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, {}> { |
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.
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.
I would suggest to use tslint:disable-next-line:variable-name and move it where it's needed.
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.
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.
Is this a common react pattern? Can you add docs or a link to a description?
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
Nice that we have a single reference to the global header now.
|
@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; |
src/app.tsx
Outdated
| created: new Date(), | ||
| owner: { | ||
| displayName: "Anonymous", | ||
| photoURL: "/static/img/anon_profile.png?", |
| "preserveConstEnums": true, | ||
| "pretty": true, | ||
| "sourceMap": true, | ||
| "allowSyntheticDefaultImports": true, |
There was a problem hiding this comment.
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.
Did you try import * as pathToRegExp from "path-to-regexp" ?
There was a problem hiding this comment.
@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.
The issue I have with this is that it breaks the type-checker.
There was a problem hiding this comment.
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.
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.
Should this be exported so it could be used in tests?
| await flush(); | ||
| assertEqual(path(), "/page/345"); | ||
| assertEqual(activePage(), "p3"); | ||
| assertEqual(matchedProps.get("p3").v, "345"); |
| message: string; | ||
| } | ||
|
|
||
| export function ErrorPage(props: ErrorPageProps) { |
There was a problem hiding this comment.
Nit: This could be done in one line...
function ErrorPage(props: { header?: string, message: string }): JSX.Element {
There was a problem hiding this comment.
max-line-length: Exceeds maximum line length of 80
|
@piscisaureus any comments? : ) |
| } | ||
|
|
||
| render() { | ||
| this.loadData(); |
There was a problem hiding this comment.
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.
@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.
as any is inappropriate here.
There was a problem hiding this comment.
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