How does it work?
Explanation of Mosaic's work mechanics
Last updated
Was this helpful?
Explanation of Mosaic's work mechanics
Last updated
Was this helpful?
This article mostly is for the contributors who are willing to enhance the Mosaic's core package's (@tilework/mosaic
) behaviour with additional functionality.
Read the code for more information, or feel free to use our to ask us for specifics!
middleware
- a method to attach a namespace to a piece of functionality and ensure the plugins work for that namespace
Extensible
- a method to ensure proper context during the construction of the given class. Important for interception of class properties being declared with during their initialisation in the constructor
setPlugins
- a method that accepts an array of modules (which are .plugin.js
files), sets the internal property and exposes it to the window object.
The middleware
function wraps functionality (further - "middlewarable") into a , and assigns a to it.
When it is called, the following happens:
The plugins are being extracted from the lib/plugins/plugin-storage
These plugins are wrapped around the initial function, thus generating a new function
This function is called on the original arguments
During the new
call, the following happens:
All of the member-property
plugins are applied to it, replacing the original properties with the ones the plugins result into.
Afterwards, when the object is used, the following happens:
When calling any member of the instance, the plugin storage is scanned for the plugins for that member, and if any are found - they are applied to the callable member before executing it
Also, the following is applied to the class itself
This is not supported
Extensible
ensures that the instance is a from the very beginning, this Proxy intercepts all members' accesses and applies plugins on the fly
The class itself is a , to ensure that calls to static properties are handled as member properties - by immediate replacement. It is a proxy only when is accessed from within its instance, otherwise it is not a proxy.