You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/tut/Fantasy.md
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,25 +7,31 @@ position: 3
7
7
8
8
# XReact Fantasy
9
9
10
-
xreact is a Functional library that can integrate FRP lib rxjs or mostjs into react. But there're still too many details you need to care while modeling UI components.
10
+
xReact is a Functional library that can integrate FRP lib rxjs or mostjs into react. But there're still too many verbose you need to care while modeling UI components.
11
11
12
12
The implement of [Fantasy Land](https://github.com/fantasyland/fantasy-land), which will change the way you model and implement UI entirely.
13
13
14
+
> The idea of FantasyX is highly inspired by [flare](http://sharkdp.github.io/purescript-flare/) by purescript
15
+
14
16
## `lift`
15
17
16
18
Let's use List as example, what `lift` does is very similar to `map`
17
19
18
20
```js
19
-
[1,2,3].map(x=>x+1) // => [2,3,4]
21
+
constf=x=> x +1
22
+
[1,2,3].map(f) // => [2,3,4]
20
23
```
21
24
25
+
It simply map `f` to every items in the list. While if we do it another way around:
26
+
22
27
```js
23
-
lift(x=>x+1)([1,2,3]) // => [2,3,4]
28
+
constlf=lift(f)
29
+
lf([1,2,3]) // => [2,3,4]
24
30
```
25
31
26
-
You should notice that both lift and map transform `x => x + 1` which should only able to apply to `Number`, to a function that can apply to `Array[Number]`
32
+
Now `lf` can take a list, apply `f` to each item, and return a new list. So `lf` is just a lifted version of `f`. You should notice that both lift and map transform `x => x + 1` which should only able to apply to `Number`, to a function that can apply to `Array<Number>`
27
33
28
-
We can now (from v2.3.0) lift a normal function to which can apply to xReact FantasyX as well.
34
+
We can now (from v2.3.0) lift a normal function(takes value and return value) to a FantasyX level function(take FantasyX and return FantasyX) as well.
29
35
30
36
Let's take a look at a really simple example, multiply 2 numbers.
31
37
@@ -37,7 +43,7 @@ function mult(a, b) {
37
43
mult(1, 2)
38
44
```
39
45
40
-
But if we need a React Component that multiply 2 numbers from 2 input box, how complicated it could be?
46
+
But if we need a React Component that multiply 2 numbers from 2 input boxes, how complicated it could be?
41
47
42
48
Now you get simply get a free FantasyX from just any normal function, via `lift`.
0 commit comments