The core concepts and their implementations as plugins build upon each other and each enhance collage by their specific features.
- The collage-fragment custom element.
- The create-context plugin
- The handshake plugin
- The direct functions plugin
- The services plugin
- The topics plugin
How the connection between arrangement and fragment works:
The connection is mediated by the custom element, since that is the point where we are in the parents code context but actually know about a specific child to connect.
A successful connection then enhances the fragments context with methods from the arrangement.
The most basic concept in collage is that of a context. At its base a context is simply the representation of a uniquely identified fragment and the connection to a potential parent.
For a more detailed description of the handshake, see Create Context plugin documentation.
To set up the communication between a fragment and an arrangement, collage performs a handshake between them.
For a more detailed description of the handshake, see Handshake plugin documentation.
Services are functions, an arrangement can provide to all the fragments (and their fragments).
For a more detailed description of the service functions, see Services plugin documentation.
Direct Functions can be called on a fragment directly by its arrangement
For a more detailed description of direct functions, see Direct Functions plugin documentation.
The Topics feature allows an easy way to subscribe to topics and publish new values to topics.
For a more detailed description of the topics plugin, see Topics plugin documentation.
With configurations an arrangement gets the possibility to configure an embedded fragment and overwrite the default configuration of it.
For a more detailed description of the config plugin, see Config plugin documentation.
The last module to be performed will trim the resulting context api to the fields that we intend a client to use.
Any internal state that may have been needed to communicate between plugin modules should not be visible in client context.
In the fragment
- collect stuff for my children
- collect my exposed functions (child functions)
- simple beacon request --> get simple beacon answer?
connectToParent
with my functions -> gain parent services- add parent stuff to context
- send
collage-initialized
event - all my fragments will initialize iframes
- create iframe
- send what is your id? as post message
- await answer
- if answer:
connectToChild
In the arrangement
- setup a beacon
- When a question arrives -> check if we have a matching fragment element (id)
- initiate
connectToChild
with the iframe in that element - send response
const definition = {
services: {},
topics: {},
configuration: {},
functions: {},
}
const context = await expose(description)
const arrangementContext = connectToArrangement(description, context)
const combined = combineContexts(context, arrangementContext)
createBeacon(combined, (question) => {
if (findFragmentInDOM(question)) {
connectToChild()
sendAnswer()
}
})
return combined
<collage-fragment context-id="1234-12344-1234">