- Platform doesn't know anything about Constructor
- Constructor doesn't know anything about Platform
- Modules are stand-alone. They do not know anything about neither Platform nor Constructor
- Modules can be used in any kind of Platform, since it does not depend on it
- Platform has to expose specific api to Modules, so if one builds such new Platform, it has to provide some properties
There is a contract between Platform and Modules, so in order to co-operate they both must follow some rules.
This is a API any Platform must expose to Modules
module- this is the core is the content ofindex.json, of actual lesson, though some meta fields might be trimmed. The must-have are:contenthintstitleidtype
- Module state information (such as whether module is in
checkmode, orreadonlymode, etc.). Platform sets those variables, and Modules react. It's really up to Module as per how to react to it, from totally ignoring it to doing something with it, the main thing is Platform has to provide it, and Platform should not really care what Modules do with them.isReadonlyisFinishedisCorrectisFinalCheckedisOnceFailedstate
path- path toindex.jsonfile. Example:lessons/L_10696assets- object containing information about assests (name, imageSize, duration, mime-type, etc.)contentState- weird thing, it seems that it holds information about state of some elements (toggleBlock), not sure whyPlatformhas to keep this statelessonApi- special object with dispatch, and other methods which Modules need, they can sometimes change something in Platform (setScrollLock,setPage), or contain information about Platform state (isMobile)lang- it speaks for itself
Platform and Modules require index.json of lesson to be of certain structure, on which they rely. Though these nuances are handled by Constructor which produces those index.json.
What Platform knows about Modules:
titletypeaudiohintsrightwrongsolution
These fields are used for different purposes inside Platform. For example, Platform accesses Modules hints field in order to display hints, thus each Module must have hints field.
Sometimes Platform needs certain information about Module, whether about its data, or its state. If data can be accessed just accessing index.json, state is harder to reach, since it lives in Modules 1. Exposing whole state, for Platform to use does not make sense, since then Modules state will have to be of certain structure, it's better if Platform does not know anything about Modules state (ideally, Modules state must be private to Modules).
And when such case arises, Modules export special functions which calculate information from its state and data, or just objects. They are imported into Platform.
What each Module must export for Platform:
isCorrect- in order for Platform pagination to display solved modules as green/reddef,map- those are needed for reduxgenCustomHints- Module must export this function if wants to display custom hints (currently, only Module utilizing this isexpression, it displays hints per element)
Footnotes
-
When we say lives in Modules, what we actually mean, is that Platform mustn't directly access Modules state. Even though technically it's possible, since Platform imports all reducers of Modules and puts them in itself, so it actually hosts state of Modules ↩