Skip to content

Commit 4e633cb

Browse files
committed
clearer project state example
1 parent f8a0f46 commit 4e633cb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,21 @@ _Note: for clarity, the diagram above excludes states and transitions relating t
233233

234234
#### Example
235235

236-
![Project state example](docs/project_state_example.png)
236+
Here's an example of how states transition.
237+
238+
Suppose a user clicks on a project, and the page starts to load with url https://scratch.mit.edu/projects/123456 .
237239

238-
For example, suppose the project state machine is currently in the `FETCHING_WITH_ID` state.
240+
Here's what will happen in the project state machine:
239241

240-
If the project state machine is given the `DONE_FETCHING_WITH_ID` action, the state will transition to the `LOADING_VM_WITH_ID` state. As part of that transition, it will store the `projectData` that it fetched while in the `FETCHING_WITH_ID` state.
242+
![Project state example](docs/project_state_example.png)
241243

242-
Once in the `LOADING_VM_WITH_ID` state, the `projectData` object is loaded into Scratch's virtual machine (the "vm"). Next, the `DONE_LOADING_VM_WITH_ID` action transitions the state from `LOADING_VM_WITH_ID` to `SHOWING_WITH_ID`. In this state, the project appears playable to the user.
244+
1. When the app first mounts, the project state is `NOT_LOADED`.
245+
2. The `SET_PROJECT_ID` redux action is dispatched (from src/lib/project-fetcher-hoc.jsx), with `projectId` set to `123456`. This transitions the state from `NOT_LOADED` to `FETCHING_WITH_ID`.
246+
3. The `FETCHING_WITH_ID` state. In src/lib/project-fetcher-hoc.jsx, the `projectId` value `123456` is used to request the data for that project from the server.
247+
4. When the server responds with the data, src/lib/project-fetcher-hoc.jsx dispatches the `DONE_FETCHING_WITH_ID` action, with `projectData` set. This transitions the state from `FETCHING_WITH_ID` to `LOADING_VM_WITH_ID`.
248+
5. The `LOADING_VM_WITH_ID` state. In src/lib/vm-manager-hoc.jsx, we load the `projectData` into Scratch's virtual machine ("the vm").
249+
6. When loading is done, src/lib/vm-manager-hoc.jsx dispatches the `DONE_LOADING_VM_WITH_ID` action. This transitions the state from `LOADING_VM_WITH_ID` to `SHOWING_WITH_ID`
250+
7. The `SHOWING_WITH_ID` state. Now the project appears normally and is playable and editable.
243251

244252
## Donate
245253
We provide [Scratch](https://scratch.mit.edu) free of charge, and want to keep it that way! Please consider making a [donation](https://secure.donationpay.org/scratchfoundation/) to support our continued engineering, design, community, and resource development efforts. Donations of any size are appreciated. Thank you!

docs/project_state_example.png

78.2 KB
Loading

0 commit comments

Comments
 (0)