Electrum
Electrum simplifies framework-agnostic declaration of React components.
It is used internally by Epsitec SA to
bridge the gap with its Xcraft toolchain and with its Lydia framework.
Where does the name Electrum come from?
Electrum is an alloy of gold and
silver used to produce ancient Lydian
coinage.
The first metal coins ever made, were of Electrum and date back to the end
of the 7th century, beginning of the 6th century BC.
THIS IS WORK IN PROGRESS
The implementation of electrum
is being modified radically.
Please wait until version has stabilized.
Linking components with their state
Let's say we want to display an article which contains the content
and information about the author. The article data might be represented
like this:
{ "article":
{ "content":
{ "title": "About typography"
, "text": "Lorem ipsum..."
, "date": "2015-12-02" }
, "author":
{ "name": "John"
, "mail": "john@doe.org" } } }
This can be loaded into a store
instance. The "article"
node will be
passed as state to the <Article>
component:
const state = store.select ('article');
return <Article state={state}/>;
The <Article>
can be implemented as a stateless function component:
import E from 'electrum';
function Article (props) {
return (
<div>
<Content {...E.link (props, 'content')} />
<Author {...E.link (props, 'author')} />
</div>
);
}
Reading state
Components will very often need to read values from the store. To make life
easier for the developer, electrum
provides a read()
method, which takes
the props
of the component and the id
of the value to read:
import E from 'electrum';
function Content (props) {
return (
<div>
<h1>{E.read (props, 'title')}</h1>
<p>{E.read (props, 'text')}</p>
</div>
);
}
Managing styles with Radium
We decided to use radium
as the way to go to inject styles into components.
By using the E
instance provided by import E from 'electrum'
), components
will automatically be configured to use radium
when they are wrapped like
this:
import E from 'electrum';
import _Button from './Button.component.js';
import _Button$styles from './Button.styles.js';
export const Button = E.wrap ('Button', _Button, _Button$styles);