Skip to content

Commit

Permalink
Merge pull request #10 from tcavenezuela/hotfix/get-method
Browse files Browse the repository at this point in the history
Hotfix/get method
  • Loading branch information
carl0shd authored Feb 5, 2024
2 parents 382c925 + 86f559b commit 7c984b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-colts-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@simconnect.js/api': patch
---

Update README.md to fix some examples
5 changes: 5 additions & 0 deletions .changeset/khaki-yaks-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@simconnect.js/api': patch
---

Fix get method prop names access
4 changes: 2 additions & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ simconnect.connect({
async function connect(handle, recvOpen) {
console.log(`Simulator connected`, recvOpen);

const [start, stop] = api.schedule(
const [start, stop] = simconnect.schedule(
(data) => {
console.log("data", data);
},
Expand Down Expand Up @@ -109,7 +109,7 @@ simconnect.connect({
retries: Infinity,
retryInterval: 5,
onConnect: () => {
api.on(SystemEvents.PAUSED, () => {
simconnect.on(SystemEvents.PAUSED, () => {
// ...
});
},
Expand Down
19 changes: 4 additions & 15 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,13 @@ export class SIMCONNECT_API {
* @returns
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(...propNames: any[]) {
get(propNames: any[]) {
if (!this.connected) throw new Error(SIM_NOT_CONNECTED);

const DATA_ID = this.nextId();
const REQUEST_ID = DATA_ID;
propNames = propNames.map((s) => s.replaceAll(`_`, ` `));
// see if this is a special, non-simconnect variable:
if (propNames.length === 1 && this.simulatorName === 'MSFS') {
const [propName] = propNames;
for (const get of this.specialGetHandlers) {
/* @ts-ignore */
if (get.supports(propName)) {
/* @ts-ignore */
return get(propName);
}
}
}
// if not, regular lookup.

const defs = propNames.map((propName) => SimVars[propName]);
this.addDataDefinitions(DATA_ID, propNames, defs);
return this.generateGetPromise(DATA_ID, REQUEST_ID, propNames, defs);
Expand Down Expand Up @@ -351,15 +340,15 @@ export class SIMCONNECT_API {
* schedule and the second function stops the schedule.
*/
schedule(
handler: (arg0: () => unknown) => void,
handler: (arg0: unknown) => void,
interval: number,
propNames: string[],
startByDefault: boolean
) {
if (!this.connected) throw new Error(SIM_NOT_CONNECTED);
let running = startByDefault;
const run = async () => {
handler(await this.get(...propNames));
handler(await this.get(propNames));
if (running) setTimeout(run, interval);
};
run();
Expand Down

0 comments on commit 7c984b1

Please sign in to comment.