Skip to content

Commit c7dcc00

Browse files
Starzustarzu
authored and
starzu
committed
More examples in README
1 parent 480d5ab commit c7dcc00

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@ Static types for the jQuery API for [Scala.js](http://www.scala-js.org/) program
77
Add the following to your SBT build:
88

99
```scala
10-
libraryDependencies += "io.udash" %%% "udash-jquery" % "0.2.0"
10+
libraryDependencies += "io.udash" %%% "udash-jquery" % "1.0.0-rc.1"
1111
```
1212

13-
then import jQuery package:
13+
then import the jQuery package:
1414

1515
```scala
1616
import io.udash.wrappers.jquery._
1717
```
1818

19-
## Example
19+
## Examples
20+
21+
```scala
22+
import io.udash.wrappers.jquery._
23+
24+
jQ("#elementId")
25+
.hide(AnimationOptions(
26+
duration = Some(3000),
27+
easing = Some(EasingFunction.linear)
28+
))
29+
.show(1500, EasingFunction.swing)
30+
```
2031

2132
```scala
2233
import io.udash.wrappers.jquery._
@@ -28,4 +39,33 @@ element.attr("example-attr") match {
2839
case Some(value) => println(s"Attribute value: $value")
2940
case None => println("Attribute not found!")
3041
}
31-
```
42+
```
43+
44+
```scala
45+
import io.udash.wrappers.jquery._
46+
47+
val callbacks = jQ.callbacks[js.Function1[(Int, Int), js.Any], (Int, Int)]()
48+
callbacks.add((t: (Int, Int)) => {
49+
val (a, b) = t
50+
jQ("#plus").append(li(s"$a + $b = ${a+b}").render)
51+
})
52+
callbacks.add((t: (Int, Int)) => {
53+
val (a, b) = t
54+
jQ("#minus").append(li(s"$a - $b = ${a-b}").render)
55+
})
56+
callbacks.add((t: (Int, Int)) => {
57+
val (a, b) = t
58+
jQ("#mul").append(li(s"$a * $b = ${a*b}").render)
59+
})
60+
callbacks.add((t: (Int, Int)) => {
61+
val (a, b) = t
62+
jQ("#div").append(li(s"$a / $b = ${a/b}").render)
63+
})
64+
65+
callbacks.fire(1, 1)
66+
callbacks.fire(3, 3)
67+
callbacks.fire(7, 4)
68+
69+
callbacks.disable()
70+
callbacks.fire(1, 2)
71+
```

0 commit comments

Comments
 (0)