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
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,5 +194,46 @@ Further reading: [Stack Overflow](https://stackoverflow.com/questions/46602286/n
194
194
You can publish the GUI to github.io so that others on the Internet can view it.
195
195
[Read the wiki for a step-by-step guide.](https://github.com/LLK/scratch-gui/wiki/Publishing-to-GitHub-Pages)
196
196
197
+
## Understanding the project state machine
198
+
199
+
Since so much code throughout scratch-gui depends on the state of the project, which goes through many different phases of loading, displaying and saving, we created a "finite state machine" to make it clear which state it is in at any moment. This is contained in the file src/reducers/project-state.js .
200
+
201
+
It can be hard to understand the code in src/reducers/project-state.js . There are several types of data and functions used, which relate to each other:
202
+
203
+
### Loading states
204
+
205
+
These include state constant strings like:
206
+
207
+
*`NOT_LOADED` (the default state),
208
+
*`ERROR`,
209
+
*`FETCHING_WITH_ID`,
210
+
*`LOADING_VM_WITH_ID`,
211
+
*`REMIXING`,
212
+
*`SHOWING_WITH_ID`,
213
+
*`SHOWING_WITHOUT_ID`,
214
+
* etc.
215
+
216
+
### Transitions
217
+
218
+
These are names for the action which causes a state change. Some examples are:
219
+
220
+
*`START_FETCHING_NEW`,
221
+
*`DONE_FETCHING_WITH_ID`,
222
+
*`DONE_LOADING_VM_WITH_ID`,
223
+
*`SET_PROJECT_ID`,
224
+
*`START_AUTO_UPDATING`,
225
+
226
+
### How transitions relate to loading states
227
+
228
+
As this diagram of the project state machine shows, various transition actions can move us from one loading state to another:
229
+
230
+

231
+
232
+
For example, suppose the project state machine is currently in the `FETCHING_WITH_ID` state.
233
+
234
+
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.
235
+
236
+
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.
237
+
197
238
## Donate
198
239
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