Skip to content

Commit 2122f81

Browse files
committed
docs
1 parent 38f531e commit 2122f81

1 file changed

Lines changed: 45 additions & 27 deletions

File tree

README.md

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88

99
Rimmel is a powerful, fast and lightweight JavaScript UI library for creating web applications using reactive streams.
1010

11-
It implements [RML](https://github.com/ReactiveHTML/reactive-markup), the Reactive Markup which makes your HTML work with streams in a seamless way.
12-
13-
## Getting started
14-
If you are new to reactive streams, there is a [3m crash-course](https://medium.com/@fourtyeighthours/the-mostly-inaccurate-crash-course-for-reactive-ui-development-w-rxjs-ddbb7e5e526e) tailored for UI development with Rimmel, arguably the simplest RxJS introduction around to get you started.
15-
16-
If you are new to the reactive and functional programming paradigms, this [interactive tutorial](https://reactivex.io/learnrx/) may be an especially useful introduction.
17-
18-
If you come from Angular, check out [this page](./docs/migrating/angular.md)<br>
19-
If you come from React, check out [this page](./docs/migrating/react.md)<br>
20-
2111
## Hello World 👋🌏🏖️😎
2212
Let's jump straight in. The "Hello World" for reactive user interfaces is the classic click counter: one button, you click it, ze counts it.
2313

@@ -28,20 +18,41 @@ Let's jump straight in. The "Hello World" for reactive user interfaces is the cl
2818
The click event from the `<button>` above is plugged into `counter` — a simple stream of events to numbers —
2919
and the output is plugged into the `<span>` element at the end.
3020

31-
No need for anything else. No need to attach, connect, disconnect, clean up or anything. Rimmel does it all for you in pure JavaScript/TypeScript without any "dark magic".
21+
```js
22+
const count = new BehaviorSubject(0).pipe(
23+
scan(x=>x+1)
24+
);
25+
26+
document.body.innerHTML = rml`
27+
<button onclick="${count}">
28+
click me (${count})
29+
</button>
30+
`;
31+
```
3232

33-
You've probably never seen anything like this before, so just go and try it:
33+
No need for anything else. No need to attach, connect, disconnect, clean up or anything. Rimmel does it all for you in pure JavaScript/TypeScript.
34+
35+
You've probably never seen anything like this before, so just go and play with it:
3436

3537
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/rimmel-click-counter)
3638

39+
## Getting started
40+
OK, let's take one step back, just in case.
41+
42+
If you are new to reactive streams, there is a [3m crash-course](https://medium.com/@fourtyeighthours/the-mostly-inaccurate-crash-course-for-reactive-ui-development-w-rxjs-ddbb7e5e526e) tailored for UI development with Rimmel, arguably the simplest RxJS introduction around to get you started.
43+
44+
If you are new to the reactive and functional programming paradigms, this [interactive tutorial](https://reactivex.io/learnrx/) may be an especially useful introduction.
45+
46+
If you come from Angular, check out [this page](./docs/migrating/angular.md)<br>
47+
If you come from React, check out [this page](./docs/migrating/react.md)<br>
3748

3849
## Stream Oriented
3950
Most JavaScript UI libraries and frameworks are designed for the imperative programming paradigm.
4051
Occasionally they may also support some aspects of reactive or functional programming, too.
4152
Third-party adapters or utility libraries can also be used to translate between each paradigm but the reality is that the imperative paradigm is their main focus and everything else was just an afterthought, severely limited, inconvenient or plain awkward to use in practice.
4253

4354
Rimmel was designed to make reactive streams just work.
44-
In the Stream Oriented paradigm you begin creating reactive streams for all your state and behaviour, then use declarative templates (e.g.: RML) to bind them to the real world. This helps writing an extremely high quality code that's also very easy to maintain.
55+
In the Stream Oriented paradigm you begin creating reactive streams for all your state and behaviour, then use declarative templates (e.g.: [RML](https://github.com/ReactiveHTML/reactive-markup)) to bind them to the real world. This helps writing an extremely high quality code that's also very easy to maintain.
4556

4657
### Everything is a Stream ☄️
4758
This is the key concept of the paradigm. Instead of creating variables, classes, object and methods that perform mutations, you create streams. A stream is optional data-in, optional processing, optional data-out. Can be sync or async and combine other streams.
@@ -60,15 +71,23 @@ target.setProperty('prop1', value);
6071
What you do instead, is you define all your application logic as streams, then you connect both ends of them to your HTML (Rimmel will know when to connect the input or the output from the context):
6172

6273
```javascript
63-
// Stream Oriented
64-
const stream = <your stream here>;
74+
// A stream-oriented component
75+
const stream = /* <your stream definition> */;
6576

6677
const template = rml`
6778
<button onclick="${stream}">click me</button>
6879
Total clicks: <b>${stream}</b>
6980
`;
7081
```
7182

83+
# A simple way to manage a complex world
84+
UI is complex: API calls that might not come back, touch events coming in thousands, user actions, sensor data. They can come in any order and you'd normally have to handle all that.
85+
86+
Stream-Oriented Programming makes complicated UI development an order of magnitude simpler to deal with, once you've learnt how to use streams. This is the promise.
87+
88+
What follows is some of the key aspects of Rimmel that make it so much simpler to deal with.
89+
90+
7291
## No Virtual DOM 🚀
7392
The concept of Virtual DOM originates from the assumption that the DOM is slow, which might appear to be the case if a framework makes a large number of unnecessary, uncontrolled updates, also known as "re-renders".
7493
In that case it may be computationally cheaper to just run those outside of the DOM.
@@ -164,13 +183,12 @@ Finally, we have two sinks where the data ends up; one as the innerHTML of the <
164183
## State doesn't exist. It's a Stream ✴️
165184
"State", as the word itself suggests, is something static, so it doesn't belong to the dynamic, interactive, reactive webapps we make every day.
166185

167-
The rationale is that "state", as represented by plain old values such as numbers, strings and objects that are stored somewhere in memory is something you almost never need to read. Not now, not in 2 seconds, not in 45 minutes, not tomorrow. You only need those when certain events happen, in order to respond.
186+
The rationale is that "state", as represented by plain old values such as numbers, strings and objects that are stored somewhere in memory is something you almost never need to read. Not now, not in 2 seconds, not in 45 minutes, not tomorrow.
168187

169-
After that, everything should go quiet, including your CPU, to keep your laptop cool until the next UI event occurs.
188+
> You only need "state" when certain events happen, in order to respond.
170189
171-
This is, in summary, the _discrete functional/reactive_ paradigm behind Observables and RxJS (as opposed to the functional-reactive paradigm in general in which state is more like a continuous flow of data over time).
190+
After that, everything should go quiet, including your CPU, to keep your laptop cool until the next UI event occurs.
172191

173-
Event-driven reactivity as modelled by Observables is therefore the perfect way to describe state as it changes through the lifetime of an application at the occurrence of various discrete UI events.
174192

175193

176194
<img src="docs/assets/how-rimmel-works-9.png" alt="State doesn't exist" style="max-width: 80vw; max-height: 30vh;">
@@ -637,10 +655,13 @@ These are perfect cases to create Custom Sinks implementing relevant design patt
637655

638656
<br>
639657

658+
Here is [an example](https://stackblitz.com/edit/rimmel-table-powersink) code with a custom sink that uses low-level DOM operations to append rows and columns to a table.
659+
640660
## Memory management 🧠
641-
If you come from some other libraries or frameworks, including "vanilla RxJS", you know you're somewhat responsible of cleaning up memory. The indiscriminate use of Observable subscriptions without proper cleanup can cause memory leaks in certain scenarios.
661+
If you come from some other libraries or frameworks, including "vanilla RxJS", but especially Angular, then you know you are responsible for cleaning up memory.
662+
Certain improper uses of Observable subscriptions in mixed-imperative programming and without proper cleanup cause memory leaks in certain scenarios.
642663

643-
Using Observables with Rimmel is trivial. All DOM subscriptions and event listeners are handled by the library behind the scenes, registered when a component is mounted and unregistered when it's removed.
664+
Using Observables with Rimmel is trivial. All DOM event listeners and subscriptions are handled by the library behind the scenes, registered when a component is mounted and unregistered when it's removed.
644665

645666
<br>
646667

@@ -651,20 +672,19 @@ A `BehaviorSubject` receives a special treatment from Rimmel in that its initial
651672

652673
```javascript
653674
import { BehaviorSubject, switchMap } from 'rxjs';
675+
import { rml, JSONDump } from 'rimmel';
654676

655677
const WaitingComponent = () =>
656678
const getData = () => fetch('https://api.example.com/data')
657679
.then(data => data.json())
658-
.then(data => `<pre>${JSON.stringify(data, null, 2)}</pre>`))
659680
;
660681

661-
662682
const stream = new BehaviorSubject('loading...').pipe(
663683
switchMap(getData)
664684
);
665685

666686
return rml`
667-
<div>${stream}</div>
687+
<div>${JSONDump(stream)}</div>
668688
`;
669689
}
670690
```
@@ -705,9 +725,7 @@ Rimmel is closely following the above standardisation initiatives and aims to al
705725
706726
# Examples, examples, examples 🛟
707727
708-
There are several collections on Stackblitz that can get you started, give you inspiration or show you advanced design patterns.
709-
710-
There are several collections on Stackblitz that can get you started, give you inspiration or show you advanced design patterns.
728+
There are several collections on Stackblitz with over 200 examples that can get you started, give you inspiration or show you advanced design patterns.
711729
712730
[The Basics](https://stackblitz.com/@dariomannu/collections/rimmel-js-getting-started) 🧺 A good place to start off. Simple examples for simple tasks.
713731

0 commit comments

Comments
 (0)