Skip to content

Commit 463128e

Browse files
committed
refactor: use type-check JS instead of TS for quickstart examples
1 parent 8adf840 commit 463128e

File tree

7 files changed

+54
-356
lines changed

7 files changed

+54
-356
lines changed

examples/quickstart/presence-sensor.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use strict";
21
/********************************************************************************
32
* Copyright (c) 2023 Contributors to the Eclipse Foundation
43
*
@@ -13,13 +12,21 @@
1312
*
1413
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1514
********************************************************************************/
15+
16+
// @ts-check
17+
18+
"use strict";
19+
1620
// This is an example Thing script which is a simple presence detector
1721
// It fires an event when it detects a person (mocked as every 5 second)
18-
const core_1 = require("@node-wot/core");
19-
const binding_mqtt_1 = require("@node-wot/binding-mqtt");
22+
23+
const { Servient } = require("@node-wot/core");
24+
const { MqttBrokerServer } = require("@node-wot/binding-mqtt");
25+
2026
// create Servient add MQTT binding with port configuration
21-
const servient = new core_1.Servient();
22-
servient.addServer(new binding_mqtt_1.MqttBrokerServer({ uri: "mqtt://test.mosquitto.org" }));
27+
const servient = new Servient();
28+
servient.addServer(new MqttBrokerServer({ uri: "mqtt://test.mosquitto.org" }));
29+
2330
servient.start().then((WoT) => {
2431
WoT.produce({
2532
title: "PresenceSensor",

examples/quickstart/simple-coffee-machine.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use strict";
21
/********************************************************************************
32
* Copyright (c) 2023 Contributors to the Eclipse Foundation
43
*
@@ -13,22 +12,36 @@
1312
*
1413
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1514
********************************************************************************/
15+
16+
// @ts-check
17+
18+
"use strict";
19+
1620
// This is an example Thing script which is a simple coffee machine.
1721
// You can order coffee and see the status of the resources
18-
const core_1 = require("@node-wot/core");
19-
const binding_http_1 = require("@node-wot/binding-http");
22+
23+
const { Servient, Helpers } = require("@node-wot/core");
24+
const { HttpServer } = require( "@node-wot/binding-http");
25+
2026
// create Servient add HTTP binding with port configuration
21-
const servient = new core_1.Servient();
27+
const servient = new Servient();
2228
servient.addServer(
23-
new binding_http_1.HttpServer({
29+
new HttpServer({
2430
port: 8081,
2531
})
2632
);
27-
core_1.Helpers.setStaticAddress("plugfest.thingweb.io"); // comment this out if you are testing locally
33+
34+
Helpers.setStaticAddress("plugfest.thingweb.io"); // comment this out if you are testing locally
35+
2836
let waterAmount = 1000;
2937
let beansAmount = 1000;
3038
let milkAmount = 1000;
31-
// promisify timeout since it does not return a promise
39+
40+
/**
41+
* Function to promisify timeout since it does not return a promise
42+
*
43+
* @param {number} ms
44+
*/
3245
function timeout(ms) {
3346
return new Promise((resolve) => setTimeout(resolve, ms));
3447
}

examples/quickstart/smart-clock.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use strict";
21
/********************************************************************************
32
* Copyright (c) 2023 Contributors to the Eclipse Foundation
43
*
@@ -13,15 +12,28 @@
1312
*
1413
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1514
********************************************************************************/
15+
16+
// @ts-check
17+
18+
"use strict";
19+
1620
// This is an example Thing which is a smart clock that runs 60 times faster than real time, where 1 hour happens in 1 minute.
17-
const core_1 = require("@node-wot/core");
18-
const binding_coap_1 = require("@node-wot/binding-coap");
21+
22+
const { Servient, Helpers } = require("@node-wot/core");
23+
const { CoapServer } = require("@node-wot/binding-coap");
24+
1925
// create Servient add CoAP binding with port configuration
20-
const servient = new core_1.Servient();
21-
servient.addServer(new binding_coap_1.CoapServer(5686));
22-
core_1.Helpers.setStaticAddress("plugfest.thingweb.io"); // comment this out if you are testing locally
26+
const servient = new Servient();
27+
servient.addServer(new CoapServer({port: 5686}));
28+
29+
Helpers.setStaticAddress("plugfest.thingweb.io"); // comment this out if you are testing locally
30+
2331
let minuteCounter = 0;
2432
let hourCounter = 0;
33+
34+
/**
35+
* @param {WoT.ExposedThing} thing
36+
*/
2537
async function timeCount(thing) {
2638
for (minuteCounter = 0; minuteCounter < 59; minuteCounter++) {
2739
// if we have <60, we can get a 15:60.
@@ -32,11 +44,13 @@ async function timeCount(thing) {
3244
hour: hourCounter,
3345
minute: minuteCounter,
3446
});
47+
3548
hourCounter++;
3649
if (hourCounter === 24) {
3750
hourCounter = 0;
3851
}
3952
}
53+
4054
servient.start().then((WoT) => {
4155
WoT.produce({
4256
title: "Smart Clock",
@@ -71,11 +85,13 @@ servient.start().then((WoT) => {
7185
minute: minuteCounter,
7286
};
7387
});
88+
7489
timeCount(thing);
7590
setInterval(async () => {
7691
timeCount(thing);
7792
thing.emitPropertyChange("time");
7893
}, 61000); // if this is 60s, we never leave the for loop
94+
7995
// expose the thing
8096
thing.expose().then(() => {
8197
console.info(thing.getThingDescription().title + " ready");

packages/examples/src/quickstart/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/examples/src/quickstart/presence-sensor.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/examples/src/quickstart/simple-coffee-machine.ts

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)