Add Table of Contents into README

This commit is contained in:
Roman Liutikov
2018-07-02 13:31:27 +03:00
committed by Nikita Prokopov
parent 059157ce8e
commit 23c62ef65f

View File

@ -2,6 +2,37 @@
Rum is a client/server library for HTML UI. In ClojureScript, it works as React wrapper, in Clojure, it is a static HTML generator.
## Table of Contents
- [Principles](#principles)
- [Comparison to other frameworks](#comparison-to-other-frameworks)
- [Whos using Rum?](#whos-using-rum)
- [Using Rum](#using-rum)
- [Defining a component](#defining-a-component)
- [Rendering component](#rendering-component)
- [Updating components manually](#updating-components-manually)
- [Reactive components](#reactive-components)
- [Components local state](#components-local-state)
- [Optimizing with shouldComponentUpdate](#optimizing-with-shouldcomponentupdate)
- [Writing your own mixin](#writing-your-own-mixin)
- [Working with atoms](#working-with-atoms)
- [Cursors](#cursors)
- [Derived atoms](#derived-atoms)
- [Interop with React](#interop-with-react)
- [Native React component](#native-react-component)
- [React keys and refs](#react-keys-and-refs)
- [Accessing DOM](#accessing-dom)
- [Custom class properties](#custom-class-properties)
- [React context](#react-context)
- [Server-side rendering](#server-side-rendering)
- [Support](#support)
- [Talks](#talks)
- [App templates](#app-templates)
- [Libraries](#libraries)
- [Examples](#examples)
- [Acknowledgements](#acknowledgements)
- [License](#license)
### Principles
**Simple semantics**: Rum is arguably smaller, simpler and more straightforward than React itself.
@ -193,7 +224,6 @@ Two things are happening here:
This will set up a watch on the `count` atom and will automatically call `rum.core/request-render` on the component each time the atom changes.
### Components local state
Sometimes you need to keep track of some mutable data just inside a component and nowhere else. Rum provides the `rum.core/local` mixin. Its a little trickier to use, so hold on:
@ -342,12 +372,11 @@ Each component can have any number of mixins:
One gotcha: dont forget to return `state` from the mixin functions. If youre using them for side-effects only, just return an unmodified `state`.
### Working with atoms
Since Rum relies a lot at components being able to efficiently update themselves in reaction to events, it includes two facilities to build architectures around Atoms and watchers.
**Cursors**
#### Cursors
If you have a complex state and need a component to interact with only a part of it, create a cursor using `(rum.core/cursor-in ref path)`. Given atom with deep nested value and path inside it, `cursor-in` will create an atom-like structure that can be used separately from main atom, but will sync changes both ways:
@ -367,7 +396,7 @@ If you have a complex state and need a component to interact with only a part of
Cursors implement `IAtom` and `IWatchable` and interface-wise are drop-in replacement for regular atoms. They work well with `rum/reactive` and `rum/react` too.
**Derived atoms**
#### Derived atoms
Use derived atoms to create “chains” and acyclic graphs of dependent atoms. `derived-atom` will:
@ -395,10 +424,9 @@ Use derived atoms to create “chains” and acyclic graphs of dependent atoms.
Derived atoms are like cursors, but can “depend on” multiple references and wont sync changes back to the source if you try to update derived atom (dont).
### Interop with React
**Native React component**
#### Native React component
You can access the raw React component by reading the states `:rum/react-component` attribute:
@ -410,7 +438,7 @@ You can access the raw React component by reading the states `:rum/react-comp
state) }
```
**React keys and refs**
#### React keys and refs
Therere three ways to specify React keys:
@ -423,6 +451,7 @@ Therere three ways to specify React keys:
(rum/with-key (my-component "args") "x")
```
3. or, you can specify `:key-fn` in a mixin to calculate key based on args at component creation time:
```clojure
@ -442,8 +471,7 @@ Refs work the same way as options 1 and 2 for keys work:
1. `[:div { :ref "x" }]`
2. `(rum/with-ref (my-component) "x")`
**Accessing DOM**
#### Accessing DOM
Therere couple of helpers that will, given state map, find stuff in it for you:
@ -453,7 +481,7 @@ Therere couple of helpers that will, given state map, find stuff in it for yo
(rum/ref-node state "x") ;; => top-level DOM node of ref-ed React component
```
**Custom class properties**
#### Custom class properties
To define arbitrary properties and methods on a component class, specify a `:class-properties` map in a mixin:
@ -471,7 +499,7 @@ To define static properties on a component class, specify a `:static-properties`
[:div]))
```
**React context**
#### React context
To define child context