You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -233,13 +233,21 @@ _Note: for clarity, the diagram above excludes states and transitions relating t
233
233
234
234
#### Example
235
235
236
-

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 .
237
239
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:
239
241
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
+

241
243
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.
243
251
244
252
## Donate
245
253
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!
0 commit comments