Skip to content

Commit

Permalink
counter example refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Sep 25, 2023
1 parent 863f27b commit f5f594e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# All Examples TODO restore when https://github.com/demergent-labs/azle/issues/1192 is resolved
# "examples/complex_types",
# "examples/counter",
# "examples/cross_canister_calls",
# "examples/cycles",
# "examples/date",
Expand Down Expand Up @@ -114,6 +113,7 @@ jobs:
"examples/candid_encoding",
"examples/complex_init",
"examples/composite_queries",
"examples/counter",
"examples/primitive_types",
"examples/principal",
"examples/query",
Expand Down
3 changes: 2 additions & 1 deletion examples/counter/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"root": "src",
"ts": "src/index.ts",
"candid": "src/index.did",
"wasm": ".azle/counter/counter.wasm.gz",
"wasm": ".azle/counter/counter.wasm",
"gzip": true,
"declarations": {
"output": "test/dfx_generated/counter",
"node_compatibility": true
Expand Down
27 changes: 12 additions & 15 deletions examples/counter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { nat64, query, Service, update } from 'azle';

export default class extends Service {
count: nat64 = 0n;

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

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

return this.count;
}
}
let count: nat64 = 0n;

export default Service({
readCount: query([], nat64, () => {
return count;
}),
incrementCount: update([], nat64, () => {
count += 1n;

return count;
})
});

0 comments on commit f5f594e

Please sign in to comment.