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
+83-39Lines changed: 83 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ position: 3
7
7
8
8
# XReact Fantasy
9
9
10
-
xreact is already a Functional library that can integrete FRP lib rxjs or mostjs into react. But it's still too many details you need to care while modeling UI components.
10
+
xreact is a Functional library that can integrete FRP lib rxjs or mostjs into react. But there're still too many details 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.
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
27
28
-
We can now (from v2.3.0) lift a normal function to xReact as well.
28
+
We can now (from v2.3.0) lift a normal function to which can apply to xReact FantasyX as well.
29
29
30
-
Let's take BMI calculator for example.
31
-
32
-
the key business logic of a BMI calculator is very simple
30
+
Let's take a look at a really simple example, multiply 2 numbers.
33
31
34
32
```js
35
-
functioncalcBMI(weight, height) {
36
-
let bmi =0
37
-
let health ='...'
38
-
if (height && weight) {
39
-
bmi = height / (weight * weight)
40
-
}
41
-
if (bmi <18.5) health ='underweight'
42
-
elseif (bmi <24.9) health ='normal'
43
-
elseif (bmi <30) health ='Overweight'
44
-
else health ='Obese'
45
-
return { bmi:bmi.toString(), health }
33
+
// Number -> Number -> Number
34
+
functionmult(a, b) {
35
+
return a * b
46
36
}
37
+
mult(1, 2)
47
38
```
48
39
49
-
The implementation doesn't seem to very Functional, but it doesn't matter since it's very low level implementation. It's a very easy to use, pure function:
40
+
But if we need a React Component that multiply 2 numbers from 2 input box, how complicated it could be?
41
+
42
+
Now you get simply get a free FantasyX from just any normal function, via `lift`.
Now we have a `xplan` of type `FantasyX`, simply apply it to a View and then you will get a React Component.
58
+
and we got a new FantasyX `XMult` with the computation built in.
59
+
60
+
`xinput` is an FantasyX abstraction of input box.
61
+
62
+
All we have so far was just a FantasyX `XMult` with computation composed inside, and we need a View to display and interact with. Here comes a really simple Stateless Component
0 commit comments