Skip to content

Commit 8cdd89d

Browse files
committed
Update documentation for 1.0
1 parent 4d3d1f9 commit 8cdd89d

File tree

20 files changed

+1629
-1172
lines changed

20 files changed

+1629
-1172
lines changed

NEO.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add usage recommendations
2+
- stateless
3+
- functorisation for polymorphic/semi-static components
4+
5+
-------------------
6+
7+
shallow renderer
8+
9+
is Callback necessary from non-render lifecycle hooks? DOM isn't used.
10+
11+
router's {dyn,}render{,R}
12+
13+
in lifecycle contexts mounted shouldn't always be available right?
14+
i.e. in componentWillMount
15+
If it's available then, is mounted the right name?
16+
17+
scalajs-bundler
18+
19+
Travis: bin/checkDevOnly
20+
Travis: use nodejs

README.md

Lines changed: 46 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,51 @@
1-
scalajs-react [neo]
1+
scalajs-react
22
=============
33

44
[![Build Status](https://travis-ci.org/japgolly/scalajs-react.svg?branch=master)](https://travis-ci.org/japgolly/scalajs-react)
55
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/japgolly/scalajs-react?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
66

7-
This branch is where a [redesign](https://github.com/japgolly/scalajs-react/issues/259) is currently taking place.
8-
At the moment, it's all in a new module called [`neo`](neo/src).
9-
10-
The v0.x.y series started as an experiment and grew organically from there.
11-
As such, it has accrued a number of annoyances and obstacles to desired improvements,
12-
that can now only be solved by a redesign.
13-
This begins a v1.x.y series and will begin with **v1.0.0**.
14-
15-
Contributions welcome.
16-
17-
# Done
18-
19-
- Component interfaces that allow any kind (JS, Scala, Clojure) of React component to be used generically.
20-
21-
This is really awesome because it allows a component to declare access to a subset of any component's state as long as it is a certain type, then satisfy it using Monocle to zoom in and/or transform along the way, even if its a JS component.
22-
23-
- Allow (any kind of) constructor transforms.
24-
- Allow (any kind of) props transforms.
25-
- Allow (any kind of) state transforms.
26-
27-
- Better Constructors
28-
- Agnostic to underlying implementation of component (JS, Scala, etc.)
29-
- Don't ask for non-existent or singleton props.
30-
- Depending on component, either don't ask for children, or ensure children are specified.
31-
- Allows possibility of even more children type-safety such as requiring exactly one child.
32-
- Input can be transformed.
33-
- Output can be transformed.
34-
- Additional raw React props fields can be configured.
35-
36-
- More transparency. No more hidden magic.
37-
- A separate `.raw` package that contains the React JS facade (without any Scala niceness).
38-
- All components expose their raw JS types.
39-
- All Scala components expose their underlying JS components.
40-
- It should be trivial to reuse `scalajs-react` components in other React libraries, and vice-versa.
41-
42-
- `JsComponent` - Import React components written in pure JS.
43-
([test JS](neo/src/test/resources/component-es3.js) & [test Scala](neo/src/test/scala/japgolly/scalajs/react/JsComponentTest.scala))
44-
45-
Importing a JS component is now a one-liner.
46-
```scala
47-
val Component = JsComponent[JsProps, Children.None, JsState]("ReactXYZ")
48-
```
49-
50-
- Type-safety for JS components that expose ad-hoc methods once mounted.
51-
You can now specify the JS facade.
52-
53-
- `JsFnComponent` - Import React functional components written in pure JS.
54-
([test JS](neo/src/test/resources/component-fn.js) & [test Scala](neo/src/test/scala/japgolly/scalajs/react/JsFnComponentTest.scala))
55-
56-
- `ScalaComponent` - Create React components in Scala.
57-
58-
- `ScalaFnComponent` - Create React functional components in Scala.
59-
60-
- Safe `PropsChildren` type and usage.
61-
62-
- Consistency wrt wrapping typed effects. Eg. `BackendScope.getDOMNode` should be `Callback`/direct just like everything else.
63-
64-
- Virtual DOM major revision.
65-
- Rewrite and simplify types. Now easier to work with internally. This no longer bears any resemblence to Scalatags and certainly can no longer be considered a fork. Scalatags was tremedously helpful in this journey so if you have a chance, give @lihaoyi a big thanks for his work.
66-
- Improved efficiency for vdom representation and creation.
67-
- Add type-safety between attributes/styles and values. Eg `^.disabled := 7` no longer compiles.
68-
- Event attributes now know which types of events they will generate. Eg `^.onMouseDown` knows to expect a mouse event and won't compile if you pass it a drag event handler.
69-
- React node array handling is safer, more efficient and has its own type with a nicer interface.
70-
- No more automatic expansion of `Seq`s. Either use `seq: _*` yourself or turn it into a `ReactArray`.
71-
- Optional vdom supported when enclosed in `Option` or `js.UndefOr`.
72-
- All vdom now has `.when(condition)` and `.unless(condition)` when will omit it unless a given condition is met. This replaces the `cond ?= (vdom)` syntax.
73-
- All vdom composes the same way, call `.apply` on what you have and specify more. This was usually the case but there were a few corner cases that had differences.
74-
- Easier and clearer access to SVG VDOM.
75-
- Manually-specified style objects now compose with other style attributes.
76-
77-
```
78-
ReactArray(...)
79-
Seq(...).toReactArray
80-
Array(...).toReactArray
81-
82-
Attr :=? Option(Value)
83-
Option(Tag | Attr | Component | Value | TagMod)
84-
(Tag | Attr | Component | Value | TagMod).when(Boolean)
85-
(Tag | Attr | Component | Value | TagMod).unless(Boolean)
86-
```
87-
88-
- Component (and constituent) mapping.
89-
- Can map props & state (at top-level, and in Unmounted & Mounted too).
90-
- Can map the constructor type.
91-
- Can map next stage (i.e. Component→Unmounted and Unmounted→Mounted).
92-
- Can change effect type in Mounted.
93-
94-
- Refs.
95-
- Remove String-based refs. React.JS has deprecated these and will remove them.
96-
- Type-safe refs to HTML/SVG tags that preserve the DOM type.
97-
- Type-safe refs to Scala components.
98-
- Type-safe refs to JS components.
99-
- Prevent refs to functional components.
100-
101-
- Revise & integrate the `extra` module.
102-
- Revise & integrate the Scalaz module.
103-
- Revise & integrate the Monocle module.
104-
- Revise & integrate the `test` module.
105-
- StateSnapshot + lens helper (#293)
106-
- Update the `gh-pages` module.
107-
- over-zealous inlining (#324)
108-
109-
# Pending
110-
111-
- Update doc.
112-
113-
# Maybe
114-
115-
- Static and dynamic props (for Scala components).
116-
Probably not as a normal Scala function is all that's really needed.
117-
There's no big need to avoid creating a new component per staic data.
118-
See also #180
119-
120-
- Anything ES6-related should be easy to add now. Please contribute if interested.
121-
- Facades over ES6-based JS classes. (I tried briefly but didn't get the JS working.)
122-
- Scala-based ES6-based classes. Because it's important to some people. (Apparently its faster but I'm yet to see any benchmarks or other evidence supporting this.)
123-
- Once the above works, it would be good to be able to choose a backend type for `ScalaComponent.build`.
124-
125-
# Release note / migration reminders
126-
127-
Refactored:
128-
* ExternalVar/ReusableVar -> StateSnapshot
129-
* ReusableVal/ReusableVal2 -> Reusable
130-
* ReusableFn(x).{set,mod}State -> ReusableFn.state(x).{set,mod}
131-
* Listenable.*
132-
* CompStatee -> StateAccess
133-
* `_ChangeData` -> `SimEvent._`
134-
* events
135-
* `[test]` ComponentTester -> RTU.{withRenderedIntoDocument,modifyProps,replaceProps}
136-
* `[test]` WithExternalCompStateAccess -> ReactTestVar#stateAccess
137-
138-
* Update in ScalaDoc:
139-
* ReactComponentB
140-
141-
* Moved into extra:
142-
* domCast
143-
* domAsHtml
144-
* domToHtml
145-
146-
* Removed completely:
147-
* tryFocus
148-
* tryTo
149-
* {set,mod}StateCB
150-
* CallbackB
151-
* ReusableFn#asVar{,R}
152-
* ReusableFn#fnA, ReusableFnA
153-
154-
* VDOM
155-
* `^.dangerouslySetInnerHtml := x` instead of `^.dangerouslySetInnerHtml(x)`.
156-
* Import `vdom.html_<^._` instead of `vdom.prefix_<^._`.
157-
* `?=` deprecated in favour of `when`/`unless`.
158-
* Change `:=` to `:=?` when the right-hand side is an `Option`.
159-
* TagMod: `+` and `compose` replaced with `apply(TagMod*)` just like tags.
160-
* Use `VdomAttr[A]("")` in place of `"".reactAttr`.
161-
* Use `VdomStyle[A]("")` in place of `"".reactStyle`.
162-
* Use `HtmlTag("")` or `HtmlTagOf[N]("")` in place of `"".reactTag`.
163-
* No more auto conversion of vdom arrays. Either use `blah: _*`, `TagMod(blah: _*)`, or `blah.toVdomArray`, `VdomArray(…)`.
164-
* Explain all the Seq => TagMod/Array gotchas; see PrefixedTest
165-
166-
Px
167-
168-
Ref usage is hugely different now
169-
170-
CompState.WriteAccess migration
171-
172-
ReactComponent{,U,M]_ migration
173-
174-
add cheatsheets
175-
176-
add usage recommendations
177-
- stateless
178-
179-
-------------------
180-
181-
shallow renderer
182-
183-
is Callback necessary from non-render lifecycle hooks?
184-
DOM isn't used, is it really confusing?
185-
186-
Rename {Read,Write}{Id,CB} in StateAccessor?
187-
188-
new releases for scalacss & test-state
189-
190-
router's {dyn,}render{,R}
7+
Lifts Facebook's [React](https://facebook.github.io/react/) library into [Scala.js](http://www.scala-js.org/) and endeavours to make it as type-safe and Scala-friendly as possible.
8+
9+
Provides (opt-in) support for pure functional programming, using [Scalaz](https://github.com/scalaz/scalaz) and [Monocle](https://github.com/julien-truffaut/Monocle).
10+
11+
Comes utility modules [`extra`](extra/) and [`test`](test/), helpful for React in Scala(.js), rather than React in JS.
12+
Includes a router, testing utils, performance utils, more.
13+
14+
##### Contents
15+
16+
- [Usage & Getting Started](doc/USAGE.md)
17+
- [VDOM](doc/VDOM.md)
18+
- [Refs](doc/REFS.md)
19+
- [The `Callback` class](doc/CALLBACK.md)
20+
- Delving deeper
21+
- [Types](doc/TYPES.md)
22+
- [Interoperability](doc/INTEROP.md)
23+
- [Functional programming](doc/FP.md)
24+
- Scala-only Utilities
25+
- [Router](doc/ROUTER.md)
26+
- [Performance Management](doc/PERFORMANCE.md)
27+
- [Other](doc/EXTRA.md)
28+
- [Testing](doc/TESTING.md)
29+
- [Live Examples & Demos](https://japgolly.github.io/scalajs-react/)
30+
- ScalaDoc: [core](https://www.javadoc.io/doc/com.github.japgolly.scalajs-react/core_sjs0.6_2.11/0.11.3) | [extra](https://www.javadoc.io/doc/com.github.japgolly.scalajs-react/extra_sjs0.6_2.11/0.11.3) | [scalaz72](https://www.javadoc.io/doc/com.github.japgolly.scalajs-react/ext-scalaz72_sjs0.6_2.12/0.11.3) | [monocle](https://www.javadoc.io/doc/com.github.japgolly.scalajs-react/ext-monocle_sjs0.6_2.12/0.11.3) | [test](https://www.javadoc.io/doc/com.github.japgolly.scalajs-react/test_sjs0.6_2.12/0.11.3)
31+
- [Changelogs](doc/changelog)[Latest](doc/changelog/0.11.3.md)
32+
33+
34+
##### External Resources
35+
36+
* Templates & Tutorials
37+
* [chandu0101 / scalajs-react-template](https://github.com/chandu0101/scalajs-react-template)
38+
* [ochrons / scalajs-spa-tutorial](https://github.com/ochrons/scalajs-spa-tutorial)
39+
* [TodoMVC example](http://todomvc.com/examples/scalajs-react)
40+
* [Scala.js and React: Building an Application for the Web](https://scala-bility.blogspot.com/2015/05/scalajs-and-react-building-application.html)
41+
42+
* Libraries
43+
* [test-state](https://github.com/japgolly/test-state/) - Integration/Functional/Property testing for scalajs-react.
44+
* [scalajs-benchmark](https://github.com/japgolly/scalajs-benchmark/)
45+
* [chandu0101 / scalajs-react-components](https://github.com/chandu0101/scalajs-react-components)
46+
* [payalabs / scalajs-react-mdl](https://github.com/payalabs/scalajs-react-mdl) - (Material Design Lite components)
47+
48+
##### Requirements:
49+
* React 15.3+
50+
* Scala 2.11 or 2.12.
51+
* Scala.JS 0.6.14+

changes.ods

-15.5 KB
Binary file not shown.

core/src/main/scala/japgolly/scalajs/react/vdom/Packages.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ object SvgAttrAndStyles extends SvgAttrAndStyles
1212
object all extends PackageBase with HtmlTags with HtmlAttrAndStyles {
1313
object svg extends SvgTags with SvgAttrAndStyles
1414
@inline def keyAttr = key
15-
// TODO @inline def refAttr = ref
1615
}
1716

1817
object html_<^ extends PackageBase {

doc/CALLBACK.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The `Callback` class encapsulates logic and side-effects that are meant to be *e
1212
- [Monadic Learning Curve](#monadic-learning-curve)
1313
- [Manual Execution](#manual-execution)
1414
- [Common Mistakes](#common-mistakes)
15+
- [Callbacks and Futures](#callbacks-and-futures)
1516

1617
Introduction
1718
============
@@ -256,7 +257,7 @@ Common Mistakes
256257
Callback.log("Incremented count by 1")
257258
}
258259
```
259-
260+
260261
FIXED:
261262
```scala
262263
val increment: Callback =
@@ -279,7 +280,7 @@ Common Mistakes
279280
CallbackTo(rule != null)
280281
}
281282
```
282-
283+
283284
FIXED:
284285
```scala
285286
val grantPrivateAccess = CallbackTo {
@@ -303,7 +304,48 @@ Common Mistakes
303304
There's no need or benefit to adding `() =>`.
304305

305306
Just pass around `Callback` instances instead. If React never chooses to execute them, they'll never be executed.
306-
307+
307308
But look, if for some reason you just really, really want to have a side-effect in the *construction* of the callback,
308309
then wrap the construction in `Callback.byName` and continue to pass around `Callback` instead of `() => Callback`.
309310

311+
312+
Callbacks and Futures
313+
=====================
314+
315+
There are a number of conversions available to convert between `Callback` and `Future`.
316+
317+
| Input | Method | Output |
318+
| -------------------------- | ---------------------- | ----------------------- |
319+
| `CallbackTo[A]` | `cb.toFuture` | `Future[A]` |
320+
| `CallbackTo[Future[A]]` | `cb.toFlatFuture` | `Future[A]` |
321+
| `=> Future[A]` | `CallbackTo(f)` | `CallbackTo[Future[A]]` |
322+
| `=> Future[CallbackTo[A]]` | `CallbackTo.future(f)` | `CallbackTo[Future[A]]` |
323+
| `=> Future[CallbackTo[A]]` | `Callback.future(f)` | `Callback` |
324+
325+
If you're looking for ways to block (eg. turning a `Callback[Future[A]]` into a `Callback[A]`),
326+
it is not supported by Scala.JS (See [#1996](https://github.com/scala-js/scala-js/issues/1996)).
327+
328+
**NOTE:** It's important that when going from `Future` to `Callback`, you're aware of when the `Future` is instantiated.
329+
330+
```scala
331+
def queryServer: Future[Data] = ???
332+
333+
def updateComponent: Future[Callback] =
334+
queryServer.map($ setState _)
335+
336+
// This is GOOD because the callback wraps the updateComponent *function*, not an instance.
337+
Callback.future(updateComponent)
338+
339+
// This is BAD because the callback wraps a single instance of updateComponent.
340+
// 1) The server will be contacted immediately instead of when the callback executes.
341+
// 2) If the callback is executed more than once, the future and old result will be reused.
342+
val f = updateComponent
343+
Callback.future(f)
344+
345+
// This is GOOD too because the future is created inside the callback.
346+
Callback.future {
347+
val f = updateComponent
348+
f.onComplete(???)
349+
f
350+
}
351+
```

0 commit comments

Comments
 (0)