Skip to content

Commit d534535

Browse files
authored
Move to es2021 (#1340)
* chore: move to es2021 fix #1267 * fixup! chore: move to es2021
1 parent 5afa858 commit d534535

8 files changed

Lines changed: 13 additions & 21 deletions

File tree

examples/scripts/countdown.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ WoT.produce({
8080
const listToDelete = [];
8181
for (const id of countdowns.keys()) {
8282
const as = countdowns.get(id);
83-
if ((as === null || as === void 0 ? void 0 : as.output) !== undefined) {
83+
if (as?.output !== undefined) {
8484
const prev = as.output;
8585
as.output--;
8686
console.log("\t" + id + ", from " + prev + " to " + as.output);
@@ -111,7 +111,6 @@ WoT.produce({
111111
});
112112
// set action handlers (using async-await)
113113
thing.setActionHandler("startCountdown", async (params, options) => {
114-
var _a;
115114
let initValue = 100;
116115
if (params != null) {
117116
const value = await params.value();
@@ -126,7 +125,7 @@ WoT.produce({
126125
};
127126
const ii = resp;
128127
console.log("init countdown value = " + JSON.stringify(resp));
129-
countdowns.set((_a = resp.href) !== null && _a !== void 0 ? _a : "", resp);
128+
countdowns.set(resp.href ?? "", resp);
130129
return ii;
131130
});
132131
thing.setActionHandler("stopCountdown", async (params, options) => {

examples/scripts/counter-client.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
********************************************************************************/
1515

1616
function getFormIndexForDecrementWithCoAP(thing) {
17-
var _a;
18-
const forms = (_a = thing.getThingDescription().actions) === null || _a === void 0 ? void 0 : _a.decrement.forms;
17+
const forms = thing.getThingDescription().actions?.decrement.forms;
1918
if (forms !== undefined) {
2019
for (let i = 0; i < forms.length; i++) {
2120
if (/^coaps?:\/\/.*/.test(forms[i].href)) {

examples/scripts/smart-coffee-machine-client.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ WoT.requestThingDescription("http://127.0.0.1:8080/smart-coffee-machine").then(a
4747
const makeCoffee = await thing.invokeAction("makeDrink", undefined, {
4848
uriVariables: { drinkId: "latte", size: "l", quantity: 3 },
4949
});
50-
const makeCoffeep = await (makeCoffee === null || makeCoffee === void 0 ? void 0 : makeCoffee.value());
50+
const makeCoffeep = await makeCoffee?.value();
5151
if (makeCoffeep.result != null) {
5252
log("Enjoy your drink!", makeCoffeep);
5353
} else {
@@ -64,9 +64,7 @@ WoT.requestThingDescription("http://127.0.0.1:8080/smart-coffee-machine").then(a
6464
time: "10:00",
6565
mode: "everyday",
6666
});
67-
const scheduledTaskp = await (scheduledTask === null || scheduledTask === void 0
68-
? void 0
69-
: scheduledTask.value());
67+
const scheduledTaskp = await scheduledTask?.value();
7068
log(scheduledTaskp.message, scheduledTaskp);
7169
// See how it has been added to the schedules property
7270
const schedules = await (await thing.readProperty("schedules")).value();

examples/scripts/smart-coffee-machine.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,8 @@ Assumes one medium americano if not specified, but time and mode are mandatory f
359359
// Check if the amount of available resources is sufficient to make a drink
360360
for (const resource in newResources) {
361361
if (newResources[resource] <= 0) {
362-
return new Promise((resolve, reject) => {
363-
thing.emitEvent("outOfResource", `Low level of ${resource}: ${newResources[resource]}%`);
364-
return { result: false, message: `${resource} level is not sufficient` };
365-
});
362+
thing.emitEvent("outOfResource", `Low level of ${resource}: ${newResources[resource]}%`);
363+
return { result: false, message: `${resource} level is not sufficient` };
366364
}
367365
}
368366
// Now store the new level of allAvailableResources
@@ -384,9 +382,7 @@ Assumes one medium americano if not specified, but time and mode are mandatory f
384382
schedules.push(paramsp);
385383
return { result: true, message: `Your schedule has been set!` };
386384
}
387-
return new Promise((resolve, reject) => {
388-
resolve({ result: false, message: `Please provide all the required parameters: time and mode.` });
389-
});
385+
return { result: false, message: `Please provide all the required parameters: time and mode.` };
390386
});
391387
// Finally expose the thing
392388
thing.expose().then(() => {

examples/security/oauth/consumer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ WoT.requestThingDescription("https://localhost:8080/oauth").then((td) => {
1616
WoT.consume(td).then(async (thing) => {
1717
try {
1818
const resp = await thing.invokeAction("sayOk");
19-
const result = await (resp === null || resp === void 0 ? void 0 : resp.value());
19+
const result = await resp?.value();
2020
console.log("oAuth token was", result);
2121
} catch (error) {
2222
console.log("It seems that I couldn't access the resource");

examples/templates/exposed-thing/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2016",
4-
"lib": ["ES2016", "dom"],
3+
"target": "ES2021",
4+
"lib": ["ES2021", "dom"],
55
"module": "commonjs",
66
"outDir": "dist",
77
"alwaysStrict": true,

packages/examples/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"outDir": "dist",
55
"rootDir": "src",
6-
"target": "ES2018",
6+
"target": "ES2021",
77
"sourceMap": false,
88
"removeComments": false
99
},

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
3+
"target": "ES2021",
44
"lib": ["dom"],
55
"skipLibCheck": false,
66
"module": "commonjs",

0 commit comments

Comments
 (0)