A simple library that provides utilities to compose your application from function-based components.
Linki's connections could be mapped into a diagram. It is technically possible to autogenerate diagrams from the code or the code from the diagrams or even visualize a working application to better understand the app and easier debugging.
Linki provides a frame for your application but consists only of typed patterns and small, common utilities function.
It prioritizes simplicity, so you know exactly what you are doing. As it is extremely simple it is very performant as well, has minimal footprint, easy to learn, maintain and extend.
A simple component that counts click events, and when the enter key is pressed, it sends the total number to save.
export const example: Component<
{ onClick: void; onKeyPress: string },
{ saveNumber: number; displayTotal: number }
> = ({ saveNumber, displayTotal }) => {
const [triggerSave, setupForSave] = link(withState(0), saveNumber);
return {
onClick: link(
throttle(1000),
reduce(count, 0),
fork(displayTotal, setupForSave)
),
onKeyPress: link(
filter(isKey("Enter")),
ignoreParam(),
triggerSave
),
};
};
- throttle - enforces a maximum number of times it passes the event downstream; time in this example no more than once per 1000 milliseconds
- reduce - returns its states on each event. It takes the reducer function. In this example, it just counts the number of incoming events.
- filter - pass only an element that matches the setup predicate. In this example, it only passes keyboard event when the "enter" key was pressed
- ignoreParam - ignores the input data but propagates the signal as an output
- withState - a processor that allows to set up state, on trigger the state is propagated to the output, in this example when enter key is pressed it passes the number of clicks on the output
The library uses three types of primitives: transformers, processors, and components. Each primitive type is based on javascript functions, and callbacks and each type get more complex. The idea is to use the least complex primitive possible to simplify application and avoid overhead.
They are used as the name suggests for data transformation. They can be easily composed using the pipe
operator.
For an input item, they immediately(synchronously) return the corresponding output item.
Transformers are used to creating data pipelines.