Skip to content

Commit 0c8edb2

Browse files
committed
Reformat even more Markdown files
1 parent d2ed1a5 commit 0c8edb2

File tree

14 files changed

+121
-24
lines changed

14 files changed

+121
-24
lines changed

docs/src/lib/lintplugin/configs.data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { URL } from 'url';
21
import lintPlugin from '@sourceacademy/lint-plugin';
32
import type { Linter } from 'eslint';
3+
import { URL } from 'url';
44

55
/**
66
* Represents the information about a single Rule

docs/src/modules/1-getting-started/5-faq.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,65 @@ title: FAQ
77

88
## Infrastructure
99

10-
### Could you explain more on the infrastructure of the modules system? Especially regarding how the bundle and tabs communicate.
11-
> Could you perhaps explain more on the program structure? Especially on how they communicate to achieve what I need.
12-
> And from what I currently understand,
13-
> 1. `bundle/**/*.ts` is where we store all logical functions
10+
### Could you explain more on the infrastructure of the modules system? Especially regarding how the bundle and tabs communicate
11+
12+
> Could you perhaps explain more on the program structure? Especially on how they communicate to achieve what I need.
13+
> And from what I currently understand,
14+
>
15+
> 1. `bundle/**/*.ts` is where we store all logical functions
1416
> 2. `tabs/**/*.tsx` is where we use all the react and jsx which will be shown in the frontend
1517
16-
A brief overview of the current infrastructure is explained [here](../4-advanced/flow/flow). However, I would like to explain in more detail how the `bundle` and `tab` interacts with `js-slang` and `cadet-frontend` respectively.
18+
A brief overview of the current infrastructure is explained [here](../4-advanced/flow/flow). However, I would like to explain in more detail how the `bundle` and `tab` interacts with `js-slang` and `cadet-frontend` respectively.
19+
20+
Firstly, a `bundle` is defined as the suite of functions that are provided by the module. More specifically, what we mean by this is that the bundle will provide all the functions and constants that are intended to be available for use by the cadet when programming in the Source language.
1721

18-
Firstly, a `bundle` is defined as the suite of functions that are provided by the module. More specifically, what we mean by this is that the bundle will provide all the functions and constants that are intended to be available for use by the cadet when programming in the Source language.
1922
```ts
2023
import { init, install_filter, video_height, video_width } from 'pix_n_flix';
2124

2225
install_filter((src, dest) => { /* implementation */ });
2326
init();
2427
```
28+
2529
An example of the code that makes use of a module written in the Source language is given above. The main objective of the `bundle` is to provide the behind the scenes implementation of the `install_filter`, `video_height`, `video_width` and `init` functions so that the cadet programming in Source language can use it as a black box. In the above example, you can find the implementations of the said functions [here](https://github.com/source-academy/modules/blob/master/src/bundles/pix_n_flix/index.ts). The `bundle` however, does not store all logical functions that is required by your module like those needed only by the tab that are not provided to the cadets.
2630

27-
A `tab` on the other hand is more formally defined as an _optional_ user interface used by the module. A module can exist without a tab. The tab exists for developers of modules to make use of Source Academy's side content tabs to display user interfaces that are used with the module's bundle. The tab can optionally choose to make use of the result returned from the evaluation of the Source code. The tab can also even be entirely not dependent on the result from the evaluation of the Source code. So how then does the `tab` make use of information from the `bundle`? The tab does this through the use of an object from `cadet-frontend` called the `debuggerContext`. When constructing the side content tabs, we would occasionally want to make use of front-end data like the code that was evaluated, the result of the code evaluated and Source version used. On `cadet-frontend`, all these information is stored within the `debuggerContext` object which is defined [here](https://github.com/source-academy/cadet-frontend/blob/master/src/commons/workspace/WorkspaceTypes.ts). Hence, all tabs will receieve the object `debuggerContext` as a component prop.
31+
A `tab` on the other hand is more formally defined as an _optional_ user interface used by the module. A module can exist without a tab. The tab exists for developers of modules to make use of Source Academy's side content tabs to display user interfaces that are used with the module's bundle. The tab can optionally choose to make use of the result returned from the evaluation of the Source code. The tab can also even be entirely not dependent on the result from the evaluation of the Source code. So how then does the `tab` make use of information from the `bundle`? The tab does this through the use of an object from `cadet-frontend` called the `debuggerContext`. When constructing the side content tabs, we would occasionally want to make use of front-end data like the code that was evaluated, the result of the code evaluated and Source version used. On `cadet-frontend`, all these information is stored within the `debuggerContext` object which is defined [here](https://github.com/source-academy/cadet-frontend/blob/master/src/commons/workspace/WorkspaceTypes.ts). Hence, all tabs will receieve the object `debuggerContext` as a component prop.
32+
33+
An example of an implementation of this is from the `pix_n_flix` module. The implementation can be found [here](https://github.com/source-academy/modules/blob/master/src/bundles/pix_n_flix/index.ts). In the module, a function `init()` is provided to the Source programmer. The specifications of the `pix_n_flix` module requires this `init()` function to be applied as the last statement of the Source program. As a result, the `js-slang` evaluator will return the return value of the `init()` function which is a JavaScript object with the type signature shown below.
2834

29-
An example of an implementation of this is from the `pix_n_flix` module. The implementation can be found [here](https://github.com/source-academy/modules/blob/master/src/bundles/pix_n_flix/index.ts). In the module, a function `init()` is provided to the Source programmer. The specifications of the `pix_n_flix` module requires this `init()` function to be applied as the last statement of the Source program. As a result, the `js-slang` evaluator will return the return value of the `init()` function which is a JavaScript object with the type signature shown below.
3035
```ts
3136
{
3237
toReplString: () => string;
3338
init: (video: HTMLVideoElement, canvas: HTMLCanvasElement, _errorLogger: () => void) => {};
3439
}
3540
```
36-
As described in the paragraphs above, this return value of the `init()` function will be stored within the `debuggerContext` in `debuggerContext.result.value`. The `tab` associated with the rendering of the video and canvas element will then render the HTMLVideoElement and HTMLCanvasElement, before creating references to the respective elements and applying the `init()` function in `debuggerContext.result.value` in the component's `componentDidMount()` method.
41+
42+
As described in the paragraphs above, this return value of the `init()` function will be stored within the `debuggerContext` in `debuggerContext.result.value`. The `tab` associated with the rendering of the video and canvas element will then render the HTMLVideoElement and HTMLCanvasElement, before creating references to the respective elements and applying the `init()` function in `debuggerContext.result.value` in the component's `componentDidMount()` method.
3743

3844
## Set Up and Configuration
3945

4046
### How do we use our own local version of the js-slang interpreter with the modules?
41-
> I have made some code changes to js-slang library and I want to test them out with my own local modules.
4247

43-
To use your local `js-slang` interpreter with your local modules, you will need to follow the steps below.
44-
1. Serve your modules on a local server, done by transpiling your modules into JavaScript (`yarn build`) and then serving them as static assets (`yarn serve`). The default url for the local server is `http://localhost:8022`. Note that `yarn serve` serves the contents of the `build` folder.
48+
> I have made some code changes to js-slang library and I want to test them out with my own local modules.
49+
50+
To use your local `js-slang` interpreter with your local modules, you will need to follow the steps below.
51+
52+
1. Serve your modules on a local server, done by transpiling your modules into JavaScript (`yarn build`) and then serving them as static assets (`yarn serve`). The default url for the local server is `http://localhost:8022`. Note that `yarn serve` serves the contents of the `build` folder.
4553
2. Ensure that your local version of `js-slang` is linked to your local `cadet-frontend`. This is achieved by `yarn link` at the local `js-slang` root folder and `yarn link js-slang` at the local `cadet-frontend` root folder.
4654
3. Ensure that your `cadet-frontend` environment variable `REACT_APP_MODULE_BACKEND_URL` is set to the address of your locally served modules server (from step 1). Again, the default url for the local server is `http://localhost:8022`.
4755
4. Start your `cadet-frontend` web server locally to test your module.
4856

4957
### Is it possible to be using modules served from more than one location simultaneously?
58+
5059
> I want to use my own modules served from `http://localhost:8022` and the official modules from `https://source-academy.github.io/modules` at the same time. Is it going to be possible?
5160
5261
It is not possible to be retrieving the modules' JavaScript files from more than one place simultaneously. The endpoint to retrieve the modules' JavaScript files from is the one in `cadet-frontend` evironment variable `REACT_APP_MODULE_BACKEND_URL` in the `.env` file. If you are using the `js-slang` library without `cadet-frontend`, the default source will be `https://source-academy.github.io/modules`.
5362

5463
## Language Specifications
5564

5665
### Can a user on Source Academy import more than one module at once?
66+
5767
> Am I able to run the following code in Source?
68+
5869
```ts
5970
import { function_a } from 'module_a';
6071
import { function_b } from 'module_b';
@@ -68,25 +79,29 @@ Yes this is possible.
6879
## Tabs
6980

7081
### Why is my Tab not spawning on Source Academy?
82+
7183
> Why is my tab not spawning on Source Academy? It is importing the functions but not spawning the tab.
7284
7385
* Check that the `toSpawn()` function in the Tab's `index.ts` returns `true` in your context.
7486
* Check that the environment variable `REACT_APP_MODULE_BACKEND_URL` of the running `cadet-frontend` web server is set to the correct url.
7587
* Check that `modules.json` in the root folder of the modules repository contains your module and your tab and that it is spelled correctly (eg. `{ module: { tabs: [ "Tab" ] } }`).
76-
* Refresh your browser with empty cache and hard reload.
88+
* Refresh your browser with empty cache and hard reload.
7789
* Build and restart your modules static server again with `yarn build` and `yarn serve`.
7890

7991
### How does the modules system handles css for the tabs?
92+
8093
> How to include css styles in the module tabs?
8194
82-
Currently, two options are supported.
95+
Currently, two options are supported.
96+
8397
* [Inline styles](https://www.w3schools.com/react/react_css.asp), where styles are added as an object to the react component's `style` prop
8498
* CSS inside JavaScript (eg. [Styled Components](https://styled-components.com/))
8599

86100
## Interaction with `js-slang`
87101

88102
### How can we switch to the Source interpreter rather than the Source transpiler?
89-
> I am modifying `js-slang`'s Source interpreter and need to change the mode of evaluation from the Source transpiler (default) to the Source interpreter.
103+
104+
> I am modifying `js-slang`'s Source interpreter and need to change the mode of evaluation from the Source transpiler (default) to the Source interpreter.
90105
91106
Include `"enable verbose";` as the first line of your program. Other functions of this setting can be found [here](https://github.com/source-academy/js-slang/blob/master/README.md#error-messages).
92107

docs/src/modules/2-bundle/2-creating/2-creating.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# Creating a Bundle
2+
23
This page contains instructions for creating a new bundle from scratch. If you are looking to edit an existing bundle refer to [these](../3-editing) instructions instead.
4+
35
## Running the Template Command
6+
47
> [!TIP]
5-
> If necessary, before running the `template` command, you can run
8+
> If necessary, before running the `template` command, you can run
9+
>
610
> ```sh
711
> yarn workspaces focus @sourceacademy/modules
812
> ```
13+
>
914
> to install **only** the dependencies required for creating your bundle.
1015
1116
To create a new bundle, use the `template` command.
1217
1318
```sh
1419
yarn template
1520
```
21+
1622
This will start an interactive prompt that will help you through the process of creating a bundle. Enter `module` to create a new bundle.
1723

1824
```txt
@@ -21,6 +27,7 @@ module
2127
```
2228

2329
Then enter the name of your new bundle. It must be in `snake_case`.
30+
2431
```txt
2532
What would you like to create? (module/tab)
2633
module
@@ -38,7 +45,9 @@ The command should have creates a new folder `src/bundles/new_bundle` with all t
3845
From there you can edit your bundle as necessary
3946

4047
## Naming your Bundle
48+
4149
The name of your bundle is what Source users will import from to actually use your bundle:
50+
4251
```ts
4352
import { func } from 'new_bundle';
4453
```

docs/src/modules/3-tabs/2-creating.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Creating a Tab
2+
23
This page contains instructions for creating a new bundle from scratch. If you are looking to edit an existing bundle refer to [these](./3-editing) instructions instead.
34

45
All tabs require at least one parent bundle. Before you create your tab, make sure you identify which bundle(s) are
56
supposed to be the parent of your tab.
67

78
## Running the Template Command
9+
810
> [!TIP]
9-
> If necessary, before running the `template` command, you can run
11+
> If necessary, before running the `template` command, you can run
12+
>
1013
> ```sh
1114
> yarn workspaces focus @sourceacademy/modules
1215
> ```
16+
>
1317
> to install **only** the dependencies required for creating your tab.
1418
1519
To create a new tab, use the `template` command:
@@ -24,7 +28,9 @@ This will start an interactive prompt that will help you through the process of
2428
What would you like to create? (module/tab)
2529
tab
2630
```
31+
2732
Then enter the name of the parent bundle. It must be a bundle that already exists.
33+
2834
```txt
2935
What would you like to create? (module/tab)
3036
tab
@@ -34,6 +40,7 @@ new_module
3440
```
3541

3642
Then enter the name of your new tab. It must be in `PascalCase`.
43+
3744
```txt
3845
What would you like to create? (module/tab)
3946
tab

docs/src/modules/3-tabs/3-editing.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# Editing an Existing Tab
2+
23
This page contains instructions for modifying an existing tab. If you are creating a new tab from scratch, refer to [these](./2-creating) instructions instead.
34

45
## Installing Dependencies
6+
57
To install **only** the dependencies required by the tab you are modifying, use the command below:
68

79
```sh
810
yarn workspaces focus @sourceacademy/Tab-[desired tab]
911
```
1012

1113
## Adding Dependencies
14+
1215
Your tab may need other Javascript packages. To add a dependency to your tab, run the command below:
16+
1317
```sh
1418
yarn add [dependency]
1519
```
1620

1721
If the dependency does not need to be present during runtime, then use:
22+
1823
```sh
1924
yarn add --dev [dependency]
2025
```
26+
2127
This adds the dependency to `devDependencies` instead.
2228

2329
> [!WARNING]
@@ -27,26 +33,30 @@ This adds the dependency to `devDependencies` instead.
2733
> [!NOTE]
2834
> There are certain dependencies that are common to all tab (like `react`). When adding such a dependency, remember to add the exact version
2935
> specified in the root repository `package.json`:
36+
>
3037
> ```sh
3138
> yarn add react@^18.3.1
3239
> ```
40+
>
3341
> You can also use the command `yarn constraints` to check if you have incorrectly specified the version of a dependency.
3442
3543
> [!NOTE]
3644
> When adding dependencies that originate from the repository (e.g `@sourceacademy/modules-lib`), use `workspace:^` as the given version:
45+
>
3746
> ```sh
3847
> yarn add @sourceacademy/modules-lib@workspace:^
3948
> ```
4049
4150
## React/UI Components
51+
4252
Tabs are written using the React (JSX) syntax. In React, each UI element is referred to as a "component". Documentation on how to create UIs and use React can be found [here](https://react.dev). Where possible,
4353
you should aim to write components using the funcional syntax.
4454
4555
::: details Functional vs Class Components
4656
Traditionally, React's functional components could not be "stateful". If a component needed to store state, it had to be written as a [class component](https://react.dev/reference/react/Component).
4757
4858
With the introduction of [hooks](https://react.dev/reference/react/hooks) in React 16, functional components could now be stateful and became the go-to method for writing React components. Officially, React now considers class components a legacy API and
49-
all new code should be written using the functional style.
59+
all new code should be written using the functional style.
5060
5161
Within this repository, many of the tabs were written before the introduction and widespread use of functional components. Regardless, you should be designing your components using the functional component syntax where possible.
5262
:::
@@ -67,11 +77,13 @@ in the root `tsconfig.json` used by tabs. `esbuild` reads from `tsconfig.json` a
6777
:::
6878
6979
### Components from the Common Library
80+
7081
There are also several React components defined under `@sourceacademy/modules-lib/tabs` that perform functions common across tabs.
7182
7283
You can see the documentation for these components [here](/lib/modules-lib/)
7384
7485
## Export Interface
86+
7587
As mentioned in the [overview](./1-overview), all tabs should export a single default export from their entry point using the `defineTab` helper from `@sourceacademy/modules-lib/tabs`:
7688
7789
```tsx
@@ -96,6 +108,7 @@ if you do not use the `defineTab` helper or if your tab is missing the default e
96108
> [!TIP]
97109
> For the Devserver to be able to accurately detect the changes you make to your tab while in hot-reload mode, you should define your component
98110
> outside of the `body` property as in the example **above** and **not** within the property as in the example below:
111+
>
99112
> ```tsx
100113
> // incorrect example
101114
> export default defineTab({
@@ -110,6 +123,7 @@ if you do not use the `defineTab` helper or if your tab is missing the default e
110123
111124
Only the default export is used by the Frontend for displaying your tab. It is not necessary to also export your components, but it can be done for testing:
112125
::: code-group
126+
113127
```tsx [index.tsx]
114128
import { defineTab } from '@sourceacademy/modules-lib/tabs';
115129
@@ -137,7 +151,9 @@ test('Matches snapshot', () => {
137151
:::
138152
139153
## Quick FAQs
154+
140155
### When to spawn the tab?
156+
141157
As mentioned, the frontend will go through the list of tabs for the bundles currently loaded and determine if it should spawn those tabs. This is done
142158
by calling the tab's `toSpawn` function (if it exists). If the function is missing, then the tab is always spawned.
143159
@@ -148,6 +164,7 @@ However, there are some cases where it makes sense to have the tab always spawn.
148164
So long as the `pix_n_flix` bundle is imported, the tab will be spawned.
149165
150166
### Can I update other UI elements in the frontend?
167+
151168
Right now, the UI is only updated once per evaluation (a limitation on the side of the frontend). This means that if code from your tab calls functions
152169
like `display`, the output of those functions won't be displayed in the main REPL. The only elements that can be changed are elements within the tab.
153170

0 commit comments

Comments
 (0)