Skip to content

Commit 5412c43

Browse files
committed
Continued development:
1. More document updates 2. Updated examples
1 parent 0c21114 commit 5412c43

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Table of Contents
1010
* <a href="#Build">Building the SDK</a>
1111
* <a href="#Run_Examples">Building and run examples</a>
1212
* <a href="#NodeJS">Node.js bindings</a>
13+
* <a href="#NodeJS_Modules">Modules</a>
1314
* <a href="#NodeJS_Integration">Integration Guidance</a>
1415
* <a href="#Express">Express.js bindings</a>
1516
* <a href="#MongoDB">MongoDB bindings</a>
@@ -53,7 +54,12 @@ MEANS.js goes to great lengths to make all the things you love about writing Sca
5354
## Node.js
5455

5556
The Node.js integration is by no means complete; however, there should be a sufficient number of
56-
modules implemented for most web applications. The following modules have been implemented thus far:
57+
modules implemented for most web applications.
58+
59+
<a name="NodeJS_Modules">
60+
#### Modules
61+
62+
The following modules have been implemented thus far:
5763

5864
* body-parser
5965
* events

examples/src/main/scala/examples/Examples.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import scala.scalajs.js.annotation.JSExportAll
1818
*/
1919
@JSExportAll
2020
object Examples extends js.JSApp {
21+
private val names = js.Array("events", "express", "http", "mongodb", "net", "timers")
2122

2223
override def main(): Unit = ()
2324

@@ -30,7 +31,7 @@ object Examples extends js.JSApp {
3031
case "net" => new NetServerTest(require)
3132
case "timers" => new IntermediateTimers(require)
3233
case arg =>
33-
console.warn(s"No example found for $arg")
34+
console.warn(s"No example found for $arg - Choose from ${names.mkString(", ")}")
3435
new IntermediateTimers(require)
3536
}
3637
}

examples/src/main/scala/examples/nodejs/timers/IntermediateTimers.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package examples.nodejs.timers
33
import com.github.ldaniels528.meansjs.nodejs._
44
import org.scalajs.dom.console
55

6+
import scala.concurrent.duration._
7+
68
/**
79
* Intermediate Timers
810
911
*/
1012
class IntermediateTimers(require: Require) {
1113

12-
val timer = setImmediate(() => console.log("Hello"))
14+
val immediate = setImmediate(() => console.log("Hello"))
15+
val delayed = setTimeout(() => console.log("World"), 1.second)
1316

1417
}

nodejs/src/main/scala/com/github/ldaniels528/meansjs/nodejs/package.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.github.ldaniels528.meansjs
22

33
import com.github.ldaniels528.meansjs.nodejs.timer._
44

5+
import scala.concurrent.duration.FiniteDuration
6+
import scala.language.implicitConversions
57
import scala.scalajs.js
68
import scala.scalajs.js.annotation.JSName
79

@@ -11,6 +13,10 @@ import scala.scalajs.js.annotation.JSName
1113
*/
1214
package object nodejs {
1315

16+
/////////////////////////////////////////////////////////////////////////////////
17+
// Built-in Properties
18+
/////////////////////////////////////////////////////////////////////////////////
19+
1420
@JSName("__dirname")
1521
@js.native
1622
object __dirname extends js.Object
@@ -67,4 +73,18 @@ package object nodejs {
6773
@JSName("unref")
6874
object unref extends UnRef
6975

76+
/**
77+
* Implicit conversation to translate durations into an integer
78+
* @param duration the given [[FiniteDuration duration]]
79+
* @return the time in milliseconds as an integer
80+
*/
81+
implicit def duration2Int(duration: FiniteDuration): Int = duration.toMillis.toInt
82+
83+
/**
84+
* Implicit conversation to translate durations into a double
85+
* @param duration the given [[FiniteDuration duration]]
86+
* @return the time in milliseconds as a double
87+
*/
88+
implicit def duration2Double(duration: FiniteDuration): Double = duration.toMillis.toDouble
89+
7090
}

0 commit comments

Comments
 (0)