The Cosmos UI is made out of two frames. Components are loaded inside an iframe for full encapsulation. Because the Playground and the Loader aren't part of the same frame, we use postMessage to communicate back and forth.
{
type: 'fixtureSelect',
component: 'Message',
fixture: 'multiline'
}{
type: 'fixtureEdit',
fixtureBody: {
// serializable stuff
}
}Includes user fixture list. Happens once per full browser refresh.
{
type: 'loaderReady',
fixtures: {
ComponentA: ['fixture1', 'fixture2'],
}
}webpack HMR updates Loader with the latest fixture list.
{
type: 'fixtureListUpdate',
fixtures: {
ComponentA: ['fixture1', 'fixture2', 'fixture3']
}
}Serializable fixture body is attached, which the Playground uses for the fixture editor.
{
type: 'fixtureLoad',
fixtureBody: {
// serializable stuff
}
}Due to state changes (local state, Redux or custom) or due to changes on disk (received by Loader via webpack HMR).
{
type: 'fixtureUpdate',
fixtureBody: {
// serializable stuff
}
}Init:
- Playground renders in loading state and Loader
<iframe>is added to DOM - Loader renders inside iframe and sends
loaderReadyevent to window.parent, along with user fixture list - Playground receives
loaderReadyevent, puts fixture list in state and exits the loading state
Selecting fixture:
- Playground sends
fixtureSelectevent to Loader with the selected component + fixture pair - Loader receives
fixtureSelectand renders corresponding component fixture (wrapped in user configured Proxy chain) - User component renders, callback
refis bubbled up to Loader andfixtureLoadevent is sent to Playground together with the serializable body of the selected fixture - Playground receives serializable fixture body, puts it in state and uses it as the JSON contents of the fixture editor