Skip to content

Commit b7bc430

Browse files
committed
Update doco for 0.10.0
Closes #172
1 parent 6cabcfc commit b7bc430

File tree

5 files changed

+206
-48
lines changed

5 files changed

+206
-48
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Includes a router, testing utils, performance utils, more.
2222
- [Performance Management](extra/PERF.md).
2323
- [Smaller stuff](extra/README.md).
2424
- [Testing](test/README.md).
25-
- [Changelogs](doc/)[Latest](doc/CHANGELOG-0.9.md).
25+
- [Changelogs](doc/)[Latest](doc/CHANGELOG-0.10.md).
2626

2727

2828
##### External Resources
@@ -41,6 +41,6 @@ Includes a router, testing utils, performance utils, more.
4141

4242

4343
##### Requirements:
44-
* React 0.12 *(0.13 probably works too, 0.14 will be fully supported when released)*
44+
* React 0.14
4545
* Scala 2.11
4646
* Scala.JS 0.6.4+

doc/CHANGELOG-0.10.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,18 @@ the render function name. Conversely, it's now always obvious what's happening b
303303
All `render*` functions take as their sole argument a function that returns a `ReactElement` (which is a `ReactComponent` or DOM element).
304304

305305
The `render` function takes a function which has as its first argument a `CompScope`,
306-
which is broadly analogous to javascript's `this`, and which scalajs-react conventionally designates with `$`.
306+
which is broadly analogous to javascript's `this`, and which scalajs-react conventionally designates with `$`.
307307

308308
|Method|Argument|Example|
309309
| --- | --- | --- | --- |
310310
|`render`|Function taking `CompScope`<br>(Component scope: analogous to javascript `this`)|`.render { $ => <.div() }`|
311311

312-
Additional `render*` convenience functions *without an underscore* specify (and unwrap) additional arguments,
313-
which scalajs-react conventionally designates as `P` for `props`, `C` for `propsChildren`, and `S` for `state`
314-
(see table below). The uppercase is not an accident: all of these are the types of generic arguments
312+
Additional `render*` convenience functions *without an underscore* specify (and unwrap) additional arguments,
313+
which scalajs-react conventionally designates as `P` for `props`, `C` for `propsChildren`, and `S` for `state`
314+
(see table below). The uppercase is not an accident: all of these are the types of generic arguments
315315
explicitly or implicitly given to `ReactComponentB`.
316316

317-
These additional `render*` functions are convenience functions, as all of these additional arguments can be
317+
These additional `render*` functions are convenience functions, as all of these additional arguments can be
318318
found as members of the `CompScope` argument.
319319

320320
E.g.:
@@ -323,16 +323,16 @@ E.g.:
323323
val p = $.props
324324
val c = $.propsChildren
325325
val s = $.state
326-
326+
327327
<.div()
328328
}
329-
329+
330330
is equivalent to:
331331

332332
.renderPCS { ($, p, c, s) =>
333333
<.div()
334334
}
335-
335+
336336
|Method|Argument|Example|
337337
| --- | --- | --- | --- |
338338
|`renderPCS`|Fn taking `CompScope`, props, children, state|`.renderPCS(($, p, c, s) => <.div())`|
@@ -343,9 +343,9 @@ is equivalent to:
343343
|`renderC` |Fn taking `CompScope`, children|`.renderC(($, c) => <.div())`|
344344
|`renderS` |Fn taking `CompScope`, state|`.renderS(($, s) => <.div())`|
345345

346-
`render*` function overloads *with* an underscore take a function which takes has only that single part of the
346+
`render*` function overloads *with* an underscore take a function which takes has only that single part of the
347347
`CompScope` called out in the function name. The `CompScope` itself is not passed to the function passed.
348-
348+
349349
|Method|Argument|Example|
350350
| --- | --- | --- | --- |
351351
|`render_P` | Fn taking only props. |`.render_P(p => <.div())`|
@@ -432,16 +432,31 @@ Unlike the `render` methods, this migration can be automated (see below).
432432

433433
* Small improvements to `ReusabilityOverlay`.
434434

435-
* Upgrade [scala-js-dom](https://github.com/scala-js/scala-js-dom) 0.8.{1 ⇒ 2}.
435+
* Upgrade [scala-js-dom](https://github.com/scala-js/scala-js-dom) from 0.8.1 to 0.8.2.
436436

437437
* Added `ReactTagOf` to provide more specific types for virtual DOM (ScalaTags).
438-
`ReactTag` is the kept the same as before for compatibility or if you don't need it.
438+
439+
`ReactTag` is the kept the same as before for compatibility or if you don't need it.
439440

440441
```scala
441442
val specific: ReactTagOf[html.Anchor] = <.a(^.href := "https://google.com", "Google")
442443
val general: ReactTag = specific
443444
```
444445

446+
* React components now have the following type members:
447+
448+
```scala
449+
type Props = P
450+
type State = S
451+
type Backend = B
452+
type DomType = N
453+
type Mounted = ReactComponentM[P, S, B, N]
454+
type Unmounted = ReactComponentU[P, S, B, N]
455+
```
456+
457+
These are in the constructors (`ReactComponentC`) which are equivalent to Scala objects.
458+
Component instances (`ReactComponentU`, `ReactComponentM`), equivalent to Scala classes, do not have these types.
459+
445460
---
446461

447462
### Migration commands

doc/FP.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
*For now, please just browse the source (it's not massive) and follow the types.*
44

5+
Callback
6+
========
7+
8+
Included is a type `CallbackTo[A]` which captures effects designated for use in React callbacks.
9+
`Callback` is `CallbackTo[Unit]` with a different companion object, full of different goodies that all return `Unit`.
10+
<br>*(See also [USAGE.md](USAGE.md).)*
11+
12+
It is roughly equivalent to `IO`/`Task` in Scalaz, Haskell's `IO` monad, etc.
13+
14+
Living in the `core` module with no FP dependencies,
15+
many ops normally provided via typeclasses (eg. `<*`, `>>=`, etc.) are built-in directly.
16+
The Scalaz module contains typeclass instances for it.
17+
518
Scalaz
619
======
720

821
```scala
9-
libraryDependencies += "com.github.japgolly.scalajs-react" %%% "ext-scalaz71" % "0.9.2"
22+
libraryDependencies += "com.github.japgolly.scalajs-react" %%% "ext-scalaz71" % "0.10.0"
1023
```
1124

1225
Included is a Scalaz module that facilitates a more functional and pure approach to React integration.
@@ -23,11 +36,10 @@ Monocle
2336
=======
2437

2538
```scala
26-
libraryDependencies += "com.github.japgolly.scalajs-react" %%% "ext-monocle" % "0.9.2"
39+
libraryDependencies += "com.github.japgolly.scalajs-react" %%% "ext-monocle" % "0.10.0"
2740
```
2841

2942
A module with a extensions for [Monocle](https://github.com/julien-truffaut/Monocle) also exists under `ext-monocle`.
3043

3144
There's one example online that demonstrates Monocle usage:
3245
[`ExternalVar` example](https://japgolly.github.io/scalajs-react/#examples/external-var).
33-

doc/TYPES.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Namely...
4848

4949
| Type | Desc |
5050
| ---- | ---- |
51-
| `ComponentScope.DuringCallbackU[P, S, +B]` | An unmounted component's `this` scope. |
52-
| `ComponentScope.DuringCallbackM[P, S, +B]` | A mounted component's `this` scope. |
53-
| `ComponentScope.WillUpdate[P, S, +B, +N]` | A component's `this` scope during `componentWillUpdate`. |
51+
| `CompScope.DuringCallbackU[P, S, +B]` | An unmounted component's `this` scope. |
52+
| `CompScope.DuringCallbackM[P, S, +B]` | A mounted component's `this` scope. |
53+
| `CompScope.WillUpdate[P, S, +B, +N]` | A component's `this` scope during `componentWillUpdate`. |
5454
| `BackendScope[P, S]` | A component's `this` scope as is available to backends. |
5555

5656
For using JS React Components, you can use follow facade interfaces.
@@ -95,10 +95,23 @@ One of the suffixes below can be added to any the ReactEvents above, to provide
9595

9696
For example, `ReactDragEventI` is a `ReactDragEvent` over a `HTMLInputElement` (an `<input>`), the same as writing `SyntheticDragEvent[HTMLInputElement]`.
9797

98+
### Component-scope access
99+
100+
To prevent issues such as
101+
backends' props/state being used in such a way that they go stale at runtime (a suprisingly easy mistake to make),
102+
component/backend scope access is as follows:
103+
104+
| Method | `BackendScope` | During Callback | External Access |
105+
| --- | --- | --- | --- |
106+
| `.props` | `CallbackTo[P]` | `P` | `P` |
107+
| `.state` | `CallbackTo[S]` | `S` | `S` |
108+
| `.setState` | `Callback` | `Callback` | `Unit` |
109+
| `.modState` | `Callback` | `Callback` | `Unit` |
110+
| `.forceUpdate` | `Callback` | `Callback` | `Unit` |
111+
98112
# Other
99113

100114
| Type | Desc |
101115
| ---- | ---- |
102-
| `ComponentStateFocus[T]` | Rather than give functions full access to a components state, you can narrow the state down to a subset and pass that around via this type. |
103116
| `Ref[+N]` | A named reference to an element in a React VDOM. (See [React: More About Refs](https://facebook.github.io/react/docs/more-about-refs.html).) |
104117
| `RefP[I, +N]` | As above but references multiple, related DOM elements and requires a parameter `I` (usually an ID) to disambiguate. |

0 commit comments

Comments
 (0)