Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit cb4f5ca

Browse files
authored
Merge pull request #232 from exoego/factory
Use factory macro to reduce cost of maintaining factory methods
2 parents ae7ad74 + c82a755 commit cb4f5ca

File tree

4 files changed

+30
-43
lines changed

4 files changed

+30
-43
lines changed
Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.scalajs.nodejs.cluster
22

3+
import com.thoughtworks.enableIf
4+
import net.exoego.scalajs.types.util.Factory
5+
36
import io.scalajs.nodejs.{GID, UID}
47

58
import scala.scalajs.js
@@ -8,6 +11,7 @@ import scala.scalajs.js.|
811
/**
912
* Cluster Settings
1013
*/
14+
@Factory
1115
@js.native
1216
trait ClusterSettings extends js.Object {
1317

@@ -30,6 +34,7 @@ trait ClusterSettings extends js.Object {
3034
*
3135
* From Node.js v13.2.0, v12.16.0.
3236
*/
37+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
3338
var serialization: String = js.native
3439

3540
/** <Number> Sets the user identity of the process. (See setuid(2).) */
@@ -46,31 +51,3 @@ trait ClusterSettings extends js.Object {
4651

4752
var windowsHide: Boolean = js.native
4853
}
49-
50-
/**
51-
* Cluster Settings Companion
52-
*/
53-
object ClusterSettings {
54-
def apply(execArgv: js.Array[String] = null,
55-
exec: String = null,
56-
args: js.Array[String] = null,
57-
silent: Boolean = false,
58-
serialization: String = "json",
59-
stdio: js.Array[js.Any] = null,
60-
inspectPort: Int | js.Function = null,
61-
cwd: String = null,
62-
windowsHide: Boolean = false
63-
): ClusterSettings = {
64-
val settings = js.Dynamic.literal()
65-
settings.updateDynamic("execArgv")(execArgv)
66-
settings.updateDynamic("exec")(exec)
67-
settings.updateDynamic("args")(args)
68-
settings.updateDynamic("silent")(silent)
69-
settings.updateDynamic("serialization")(serialization)
70-
settings.updateDynamic("stdio")(stdio)
71-
settings.updateDynamic("inspectPort")(inspectPort.asInstanceOf[js.Any])
72-
settings.updateDynamic("cwd")(cwd)
73-
settings.updateDynamic("windowsHide")(windowsHide)
74-
settings.asInstanceOf[ClusterSettings]
75-
}
76-
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
package io.scalajs.nodejs.crypto
22

33
import scala.scalajs.js
4+
import net.exoego.scalajs.types.util.Factory
45

6+
@Factory
57
trait DiffieHellmanOptions {
68
var privateKey: KeyObject
79
var publicKey: KeyObject
810
}
9-
10-
object DiffieHellmanOptions {
11-
def apply(
12-
privateKey: KeyObject,
13-
publicKey: KeyObject
14-
): DiffieHellmanOptions = {
15-
val obj = js.Dynamic.literal(
16-
"privateKey" -> privateKey,
17-
"publicKey" -> publicKey
18-
)
19-
obj.asInstanceOf[DiffieHellmanOptions]
20-
}
21-
}

app/nodejs-v10/src/test/scala/io/scalajs/nodejs/cluster/ClusterTest.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ import scala.scalajs.js
77
import org.scalatest.funspec.AnyFunSpec
88

99
class ClusterTest extends AnyFunSpec {
10+
describe("ClusterSettings") {
11+
it("can be instantiated") {
12+
val settings: ClusterSettings = ClusterSettings(
13+
cwd = "/home/user",
14+
exec = "ls",
15+
execArgv = js.Array(),
16+
args = js.Array(),
17+
gid = 1,
18+
uid = 2,
19+
inspectPort = 3,
20+
stdio = js.Array(),
21+
windowsHide = false,
22+
silent = true
23+
)
24+
assert(settings.silent === true)
25+
assert(settings.gid === 1)
26+
}
27+
}
28+
1029
describe("Cluster") {
1130
it("cluster should be master") {
1231
assert(Cluster.isMaster)

project/Dependencies.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ object Dependencies {
1616
val app = Def.setting(
1717
Seq(
1818
scalaReflect.value,
19-
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
20-
"com.thoughtworks.enableIf" %% "enableif" % "1.1.7"
19+
"net.exoego" %%% "scalajs-types-util" % "0.1.0",
20+
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
21+
"com.thoughtworks.enableIf" %% "enableif" % "1.1.7"
2122
)
2223
)
24+
2325
}

0 commit comments

Comments
 (0)