Skip to content

Commit cb22ae9

Browse files
committed
update the docs
1 parent a1dd5a2 commit cb22ae9

File tree

8 files changed

+118
-211
lines changed

8 files changed

+118
-211
lines changed

docs/Issue Triage.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
## Issue Triage
2+
23
Contributors with sufficient permissions on the CoCalc repo can help by adding
34
labels to triage issues:
45

5-
* Yellow, **A**-prefixed labels state which **area** of CoCalc the issue relates to.
6+
- Yellow, **A**-prefixed labels state which **area** of CoCalc the issue relates to.
67
Answers the question: "Where should I be looking?"
78

8-
* Green, **E**-prefixed labels explain the type of **experience** necessary
9+
- Green, **E**-prefixed labels explain the type of **experience** necessary
910
to fix the issue.
1011
Answers the question "What kind of effort is necessary?"
1112

12-
* Red, **I**-prefixed labels indicate the **importance** (relevance) of the issue.
13+
- Red, **I**-prefixed labels indicate the **importance** (relevance) of the issue.
1314
Answers the question: "Why is this important?"
1415

15-
* **M** is market segment priority.
16+
- Orange, **P**-prefixed labels indicate a bug's **priority**.
1617

17-
* Orange, **P**-prefixed labels indicate a bug's **priority**.
18+
- **M** is market segment priority. (ws: these are confusing and should be merged with the P- priorities)
1819

19-
* The purple **meta** label denotes a list of issues collected from other categories.
20+
- The purple **meta** label denotes a list of issues collected from other categories.
2021

21-
* The black, **blocked** label denotes an issue blocked by another.
22+
- The black, **blocked** label denotes an issue blocked by another.
2223

23-
* Finally, **upstream** signals the problem is related to a library, usually includes a link to another issue.
24+
- Finally, **upstream** signals the problem is related to a library, usually includes a link to another issue.
2425

2526
If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
2627

27-
[eeasy]:https://github.com/sagemathinc/cocalc/labels/E-easy
28+
[eeasy]: https://github.com/sagemathinc/cocalc/labels/E-easy
2829

2930
### List of labels and their descriptions
31+
3032
Most tags should be self explanatory but some can be unclear. If you're unsure what a label means how it's different from another email John Jeng at [email protected]. He'll probably add it to the description here.
3133

3234
- `blocked` -- Always link what the issue is blocked by.
@@ -37,5 +39,4 @@ Most tags should be self explanatory but some can be unclear. If you're unsure w
3739
- `I-software request` -- Requests for adding something to be installed in CoCalc by default.
3840
- `I-UA` -- Text that needs to be reworded or a tip that needs to get written.
3941

40-
4142
Inspired by [Rust's triage system](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#issue-triage).

docs/README.md

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
# Guidelines
2-
This collection of files provides general knowledge for working with the CoCalc.
3-
4-
**WARNING (June 2021): we haven't looked at this in years, and it is probably all wrong.**
5-
6-
Ask clarifying questions and update this as you go.
7-
8-
# Webapp Code Layout
9-
`entry-point.coffee`
10-
- `desktop_app.cjsx` / `mobile_app.cjsx`
11-
- Projects View (`projects.cjsx`)
12-
- Account View (`account.cjsx`)
13-
- Project View (`project_page.cjsx`)
14-
- About View (`r_help.cjsx`)
152

16-
Additionally, it has top level widget components:
17-
- Help
18-
- File Notifications (`file_use.cjsx`)
19-
- Connection Status
20-
21-
22-
# External Resources
23-
HTML/CSS
24-
- [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/)
3+
This collection of files provides general knowledge for working with the CoCalc.
254

26-
Redux:
27-
- [Getting Started](https://egghead.io/courses/getting-started-with-redux)
28-
- [Idiomatic Redux](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)
29-
- [Why you might not need redux](https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367#.g6zxcajc5)
5+
Last Updated: September 2024.

docs/Random Notes.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

docs/STYLE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# CoCalc Style Guide
2+
3+
## Language (Javascript/Typescript/Python)
4+
5+
- Prettier: Use the _defaults_ with the latest version of prettier on all of our Javascript and Typescript code. Use yapf for Python.
6+
7+
- NOTE: prettier's defaults change over time, but we don't ever just run it on our full massive codebase.
8+
9+
- Typescript: Always prefer Typescript over Javascript and CoffeeScript
10+
11+
- NOTE: there's still some coffeescript code in CoCalc; it's terrifying and should all be rewritten in Typescript.
12+
13+
- Variable Names: Use the standard Javascript camelCase convention for variable names, unless there is a good reason otherwise. Good reasons include: variable names that are also used in PostgreSQL and interop with Python (lower case with underscores).
14+
15+
- NOTE: there's a lot of Javascript code in cocalc that uses Python conventions. Long ago Nicholas R. argued "by using Python conventions we can easily distinguish our code from other code"; in retrospect, this was a bad argument, and only serves to make Javascript devs less comfortable in our codebase, and make our code look weird compared to most Javascript code. Rewrite it.
16+
17+
- Javascript Methods: Prefer arrow functions for methods of classes.
18+
19+
- it's standard
20+
- avoids subtle problems involving "this" binding
21+
- easier to search for function definition in editor
22+
- NOTE: there's a lot of code in cocalc that uses non-arrow-functions; rewrite it and don't add more of this.
23+
24+
- Async Programming: Prefer async/await to callbacks if at all possible.
25+
26+
- NOTE: CoCalc used to not use async/await or promises at all, so there is still some code that uses the callback [async library](https://github.com/caolan/async). This code is terrifying, and it should all be rewritten.
27+
28+
## React
29+
30+
- Functional Components and hooks: Always prefer functional components with hooks over class components
31+
32+
- NOTE: there are still a lot of class components in cocalc; rewrite them.
33+
34+
- Use the style of https://react.dev/learn/typescript for React with Typescript:
35+
- typescript detects unused props,
36+
- defaults are natural and do not need MyButton.defaultProps, which is deprecated,
37+
- uses minimal notation (less characters typed),
38+
- very common in tutorials and other code
39+
- NOTE: a lot of our code used to be class components, hence still is written like `prop.[propname]`
40+
41+
In particular, use
42+
43+
```ts
44+
function MyButton({ title, disabled }: MyButtonProps) {
45+
return <button disabled={disabled}>{title}</button>;
46+
}
47+
```
48+
49+
and do NOT use
50+
51+
```ts
52+
function MyButton(props: MyButtonProps) {
53+
return <button disabled={props.disabled}>{props.title}</button>;
54+
}
55+
```
56+
57+
or
58+
59+
```ts
60+
const MyButton: React.FC<MyButtonProps> = (props) => {
61+
return <button disabled={props.disabled}>{props.title}</button>;
62+
};
63+
```
64+
65+
- Memoization: avoid using `React.memo`
66+
67+
- it leads to subtle bugs
68+
- it's far better to render 20 items slowly, e.g., using virtualization, then to render 20000 items quickly
69+
- NOTE: there's 100\+ uses of React.memo in cocalc right now; I'm not happy with this, though I wrote them. It's almost always a bad idea.
70+
71+
## UI Design
72+
73+
- As much as possible, use [Antd components](https://ant.design/) in the standard way.
74+
75+
- Avoid doing new design if possible; use the conventions and components of Antd.
76+
- If there is a cancel button next to another button, then cancel goes first, following the Antd convention, e.g., see Popconfirm.
77+
- NOTE: We wrote a lot of custom components, e.g., for number input, before switching fully to Antd, and those are still partly in use. Rewrite all of that to use Antd.
78+
79+
- Bootstrap:
80+
- CoCalc used to use jquery + bootstrap (way before react even existed!) for everything, and that's still in use for some things today (e.g., Sage Worksheets). Rewrite or delete all this.
81+
- CoCalc also used to use react-bootstrap, and sadly still does. Get rid of this.
82+

docs/Understanding Editors.md

Lines changed: 18 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,58 @@
11
# Editors and Widgets
22

33
## Editor
4-
A file editor uses `register` from `project_file.coffee`.
4+
5+
A file editor uses `register`.
56
A family of file editors is the set of editors which use the same store.
6-
Each family of editors has its own folder inside `smc-webapp/`.
7-
Inside this folder is typically the following
8-
- main.cjsx
9-
- register.coffee
10-
- actions.coffee
11-
- store.coffee
12-
- README.md
13-
14-
Additional supporting files are also common:
15-
- info.coffee
16-
- styles.coffee
17-
- util.coffee
7+
Each family of editors has its own folder inside `packages/frontend/`.
188

199
Treat these folders somewhat like modules.
20-
Typically you will only be importing from `main.cjsx` and `register.coffee`.
21-
22-
## Widget
23-
Widgets stand alone and do not call `register`.
24-
See "smc-webapp/widget-markdown-input/" for an example.
2510

2611
## Actions, Tables, Stores, Oh My!
12+
2713
We use
2814
CQRS = command query responsibility segregation.
2915

30-
It means that you have two different things you communicate with (e.g., "Actions" and "Store"). One is used only for commands (=actions). The other is used only to get out data (=store). Segregation means they are completely separate. It's the design pattern we're using.
16+
It means that you have two different things you communicate with \(e.g., "Actions" and "Store"\). One is used only for commands \(=actions\). The other is used only to get out data \(=store\). Segregation means they are separate. It's the design pattern we're using.
3117

3218
If something doesn't fit into that at all, and you don't want to change the store or UI to reflect that, then that something should be somewhere else -- not in actions or store.
33-
CQRS = command query responsibility segregation.
3419

3520
### Stores
21+
3622
- Store functions should always be pure functions
3723

38-
Computed values are
39-
- Only get called when a component is rendered which depends on the function
40-
- Callable from outside React code
41-
- Not stored in the redux state. Maintain redux state as pure data
42-
43-
```ts
44-
{redux, computed, depends, rtypes} = require('app-state-framework')
45-
redux.createStore
46-
name: 'account'
47-
48-
# state types without a defined selector default to
49-
# @get('key_name') from the store
50-
# Prefer to write store.get('key_name') to be explict
51-
stateTypes :
52-
time : rtypes.string
53-
user_type : rtypes.string
54-
first_name : rtypes.string
55-
last_name : rtypes.string
56-
full_name : computed rtypes.string
57-
greetings : computed rtypes.string
58-
59-
# Define the dependencies of computed values
60-
full_name: depends('first_name', 'last_name') ->
61-
return "#{@first_name} + #{@last_name}"
62-
63-
# Computed values may call other computed values
64-
greeting: depends('full_name', 'time') ->
65-
return "Hello #{@full_name} good #{get_english_time_period_name(@time)}"
66-
67-
# Define private functions outside of the store declaration
68-
get_english_time_period_name: (time_of_day) ->
69-
# ... some computation
70-
71-
```
72-
Importing them in a high level component:
73-
```coffee
74-
ProjectPage = rclass
75-
reduxProps:
76-
account :
77-
full_name : rtypes.string
78-
greeting : rtypes.string
79-
80-
```
81-
Importing values from outside stores
82-
```coffee
83-
redux.createStore
84-
name: "project_store"
85-
86-
# Declares what values to import from other stores
87-
# These are not available using reduxProps but are
88-
# available as dependencies for computed values
89-
reduxState:
90-
account :
91-
full_name : rtypes.string
92-
93-
stateTypes:
94-
shown_greeting : computed rtypes.string
95-
96-
shown_greeting: depends('full_name') ->
97-
return "Hello, " + @full_name
98-
```
99-
Run time store definitions can be created as follows:
100-
```coffee
101-
create_project_store_def = (name, project_id) ->
102-
name: name
103-
104-
project_id: project_id
105-
```
24+
Computed values are used in a few places. They were a bad idea and all code that uses them should be rewritten. React hooks solve the same problem in a much better way.
10625

10726
### Actions
108-
Actions are called to make state changes.
109-
They do not directly manipulate the UI.
11027

28+
Actions are called to make state changes. They do not directly manipulate the UI.
11129

11230
## Q and A
11331

114-
* [hsy]> How to change a value in a store? What patterns are preferred?
115-
116-
* [hsy]> What are the steps to make a react component actually "react" to changes in a given store?
117-
* preparation step:
118-
* setup step:
119-
* details to take care of? (e.g. control exactly when to re-render)
12032

12133
The following questions are specific for projects, but are meant to be general:
12234

123-
* not project related, maybe callback, maybe return value, doesn't change store → misc
35+
- not project related, maybe callback, maybe return value, doesn't change store → misc
12436

125-
It depends. misc is pure javascript and generally just stuff that could be used on both the frontend and backend and doesn't have anything to do with sage_client communication. It's utility functions.
37+
It depends. misc is pure javascript and generally just stuff that could be used on both the frontend and backend and doesn't have anything to do with sage_client communication. It's utility functions.
12638

127-
* project related, maybe callback, no return value, doesn't change store → store ? (e.g. `ensure_directory_exists` ?)
39+
- project related, maybe callback, no return value, doesn't change store → store ? (e.g. `ensure_directory_exists` ?)
12840

129-
No. The methods of the store should all be "pure" functions of the immutable js state. There should be no callbacks ever, and nothing that should have any impact on any state anywhere. The store is a container of state and the interface is "ways to get at that state". (Exception: there is a method called "wait", which calls a callback when a certain condition on the store holds.)
41+
No. The methods of the store should all be "pure" functions of the immutable js state. There should be no callbacks ever, and nothing that should have any impact on any state anywhere. The store is a container of state and the interface is "ways to get at that state". (Exception: there is a method called "wait", which calls a callback when a certain condition on the store holds.)
13042

131-
* project related, maybe callback, has return value, doesn't change store → somewhere else ?
43+
- project related, maybe callback, has return value, doesn't change store → somewhere else ?
13244

133-
Somewhere else, e.g,. a module scope function or class or function in client.coffee. We want to minimize these as much as possible, as they are harder to reason about, but obviously sometimes they are necessary. Example: synctables involve tons of such methods.
45+
Somewhere else, e.g,. a module scope function or class or function in client.coffee. We want to minimize these as much as possible, as they are harder to reason about, but obviously sometimes they are necessary. Example: synctables involve tons of such methods.
13446

135-
* project related, no callback, no return value, changes store → action
47+
- project related, no callback, no return value, changes store → action
13648

137-
Yes, that's the ideal case. These can of course be asynchronous functions -- e.g., copying a file -- but rather than expressing what happens as it progresses via callback(s), the instead update the store as the run. Then the UI can display what happens (or not).
49+
Yes, that's the ideal case. These can of course be asynchronous functions -- e.g., copying a file -- but rather than expressing what happens as it progresses via callback(s), the instead update the store as the run. Then the UI can display what happens (or not).
13850

139-
* project related, has callback, no return value, maybe changes store → action, but only for "internal" methods
51+
- project related, has callback, no return value, maybe changes store → action, but only for "internal" methods
14052

14153
Yes, to write clean code the non-public api for Actions can have all kinds of such "traditional" methods.
14254

143-
* project related, no callback, has return value, changes store → shouldn't exist at all
55+
- project related, no callback, has return value, changes store → shouldn't exist at all
14456

14557
Yes, exactly.
14658

docs/Writing Components.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)