Skip to content

Instantly share code, notes, and snippets.

@amirfefer
Last active December 5, 2018 12:37
Show Gist options
  • Save amirfefer/e7df1e0a16e61309cf265ffa49a81643 to your computer and use it in GitHub Desktop.
Save amirfefer/e7df1e0a16e61309cf265ffa49a81643 to your computer and use it in GitHub Desktop.
Expandable component architecture

Hello everyone,

As we all know, plugins need the ability to alter pages on foreman core.
To achieve that, developers mostly use deface, which allows you to change DOM dynamically.

While deface works well with rails views, we should not use it on react components.
It changes the real DOM on server rendering, while a react component relay on the virtual DOM,
which means - changes in the real DOM won't affect the virtual DOM.

Recently, the UI team gather up with some ideas.
We took inspration from react-slot-fill

<Slot> - Extenable point in a component - used by foreman core.
<Fill>- Fils a slot with a JSX content - used by plugins.

a slot will use an internal registry, that globally manages the extendable points.

a fill component will have two filling options:

  1. Replacing - replace the entire slot's content.
  2. Appending - append content to a slot, therefore plugins can add content to the same slot.

For example, a plugin appends a button on the Notification Drawer's footer

<NotificationDrawer> 
//content
<Slot id='notification-drawer-footer` appendable />
</NotificationDrawer>

Plugin:

<Fill target='notification-drawer-footer`>
  <Button> Appended button ! </Button>
</Fill>   

This architecture allows foreman core to be more opinionated with extending pages.
Which personally I guess it is a great advantage from core perspective.
However it does reduce plugins ability to do whatever they want on existing pages / components,
so it would be a challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment