Skip to content

Commit

Permalink
Merge pull request #2048 from demergent-labs/class_context
Browse files Browse the repository at this point in the history
Class context
  • Loading branch information
lastmjs authored Sep 1, 2024
2 parents 71de06a + 29de7fa commit 17ca7d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/build/stable/commands/compile/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getPrelude(main: string): string {
import { DidVisitor, getDefaultVisitorData, IDL, toDidString } from 'azle';
import Canister from './${main}';
import * as Canister from './${main}';
${handleClassApiCanister()}
`;
Expand All @@ -24,7 +24,7 @@ function getPrelude(main: string): string {
export function handleClassApiCanister(): string {
return /*TS*/ `
if (globalThis._azleNodeWasmEnvironment === false) {
const canisterClassInstance = new Canister();
const canisterClassInstance = new Canister.default();
globalThis._azleCanisterClassInstance = canisterClassInstance;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/end_to_end/candid_rpc/class_syntax/counter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { IDL, query, update } from 'azle';

let count: bigint = 0n;

export default class {
count: bigint = 0n;

@query([], IDL.Nat64)
readCount(): bigint {
return count;
return this.count;
}

@update([], IDL.Nat64)
incrementCount(): bigint {
count += 1n;
this.count += 1n;

return count;
return this.count;
}
}

0 comments on commit 17ca7d7

Please sign in to comment.