mosaic
  • Overview
  • Integration
    • Next.js
    • Create React App
    • Webpack
  • Getting started
    • Extensions
    • Themes
  • Tutorials
    • Mosaic + React
    • Mosaic + Webpack
  • Install an extension
    • Install a local extension
    • Install with a package manager
    • Enable or disable an extension
  • Develop an extension
    • Anatomy of an extension
    • Namespaces
    • Runtime plugins
    • Build configuration plugins
  • CRA features
    • CRACO plugins
  • Next.js features
    • Styles
    • Pages
    • Common props
  • Architecture examples
    • Router
  • Themes
    • Parent theme system
    • File shadowing
  • Experimental
    • Module preferences
    • File provisioning
  • in-depth
    • How does it work?
Powered by GitBook
On this page
  • Features
  • How ?

Was this helpful?

  1. in-depth

How does it work?

Explanation of Mosaic's work mechanics

PreviousFile provisioning

Last updated 3 years ago

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!

Features

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.

How ?

The middleware function wraps functionality (further - "middlewarable") into a , and assigns a to it.

If the middlewarable is a function

When it is called, the following happens:

  1. The plugins are being extracted from the lib/plugins/plugin-storage

  2. These plugins are wrapped around the initial function, thus generating a new function

  3. This function is called on the original arguments

If the middlewarable is a class

During the new call, the following happens:

  1. 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:

  1. 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

If the middlewarable is a primitive

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.

Github Discussions
class property syntax
Proxy
namespace
Proxy
Proxy