Skip to content

Commit

Permalink
Align spacing with Jordan's examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dansteren committed Sep 26, 2023
1 parent cde7785 commit 3022db4
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 49 deletions.
4 changes: 0 additions & 4 deletions examples/motoko_examples/calc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ export default Service({

return cell;
}),

sub: update([int], int, (n) => {
cell -= n;

return cell;
}),

mul: update([int], int, (n) => {
cell *= n;

return cell;
}),

div: update([int], Opt(int), (n) => {
if (n === 0n) {
return None;
Expand All @@ -29,7 +26,6 @@ export default Service({
return Some(cell);
}
}),

clearall: update([], Void, () => {
cell = 0n;
})
Expand Down
2 changes: 0 additions & 2 deletions examples/motoko_examples/counter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ export default Service({
get: query([], nat, () => {
return counter;
}),

set: update([nat], Void, (n) => {
counter = n;
}),

inc: update([], Void, () => {
counter += 1n;
})
Expand Down
3 changes: 0 additions & 3 deletions examples/motoko_examples/http_counter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default Service({
init: init([], () => {
stableStorage.insert('counter', 0n);
}),

http_request: query([HttpRequest], HttpResponse, (req) => {
console.log('Hello from http_request');

Expand Down Expand Up @@ -141,7 +140,6 @@ export default Service({
upgrade: None
};
}),

http_request_update: update([HttpRequest], HttpResponse, (req) => {
if (req.method === 'POST') {
const counterOpt = stableStorage.get('counter');
Expand Down Expand Up @@ -196,7 +194,6 @@ export default Service({
upgrade: None
};
}),

http_streaming: query([Token], StreamingCallbackHttpResponse, (token) => {
console.log('Hello from http_streaming');
switch (token.arbitrary_data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ export default Service({

return counter;
}),

getCount: query([], nat, () => {
return counter;
}),

reset: update([], nat, () => {
counter = 0n;

Expand Down
3 changes: 0 additions & 3 deletions examples/motoko_examples/persistent-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default Service({
init: init([], () => {
stableStorage.insert('counter', 0n);
}),

increment: update([], nat, () => {
const counterOpt = stableStorage.get('counter');
const counter =
Expand All @@ -27,7 +26,6 @@ export default Service({

return counter;
}),

get: query([], nat, () => {
const counterOpt = stableStorage.get('counter');
const counter =
Expand All @@ -37,7 +35,6 @@ export default Service({

return counter;
}),

reset: update([], nat, () => {
stableStorage.insert('counter', 0n);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default Service({
insert: update([text, Entry], Void, (name, entry) => {
phoneBook.set(name, entry);
}),

lookup: query([text], Opt(Entry), (name) => {
const entryOrUndefined = phoneBook.get(name);

Expand Down
4 changes: 0 additions & 4 deletions examples/motoko_examples/simple-to-do/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default Service({
getTodos: query([], Vec(ToDo), () => {
return Array.from(todos.values());
}),

// Returns the ID that was given to the ToDo item
addTodo: update([text], nat, (description) => {
const id = nextId;
Expand All @@ -34,7 +33,6 @@ export default Service({

return id;
}),

completeTodo: update([nat], Void, (id) => {
let todo = todos.get(id);

Expand All @@ -45,7 +43,6 @@ export default Service({
});
}
}),

showTodos: query([], text, () => {
let output = '\n___TO-DOs___';
for (const todoEntry of [...todos]) {
Expand All @@ -56,7 +53,6 @@ export default Service({
}
return output;
}),

clearCompleted: update([], Void, () => {
// NOTE: this syntax isn't supported in Boa. If we revert to using Boa
// we'll need to revert the syntax to:
Expand Down
3 changes: 0 additions & 3 deletions examples/motoko_examples/superheroes/src/superheroes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export default Service({

return superheroId;
}),

// Read a superhero.
read: query([SuperheroId], Opt(Superhero), (superheroId) => {
const superheroOrUndefined = superheroes.get(superheroId);
return superheroOrUndefined ? Some(superheroOrUndefined) : None;
}),

// Update a superhero.
update: update([SuperheroId, Superhero], bool, (superheroId, superhero) => {
let result = superheroes.get(superheroId);
Expand All @@ -66,7 +64,6 @@ export default Service({

return !!result;
}),

// Delete a superhero.
deleteHero: update([SuperheroId], bool, (superheroId) => {
let result = superheroes.get(superheroId);
Expand Down
6 changes: 0 additions & 6 deletions examples/motoko_examples/whoami/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,23 @@ export default Service({
install = ic.caller();
someone = somebody;
}),

// Manually re-save these variables after new deploys.
postUpgrade: postUpgrade([principal], (somebody) => {
install = ic.caller();
someone = somebody;
}),

// Return the principal identifier of the wallet canister that installed this
// canister.
installer: query([], principal, () => {
return install;
}),

// Return the principal identifier that was provided as an installation
// argument to this canister.
argument: query([], principal, () => {
return someone;
}),

// Return the principal identifier of the caller of this method.
whoami,

// Return the principal identifier of this canister.
id: update([], principal, async () => {
// TODO This is not an ideal solution but will work for now
Expand All @@ -54,7 +49,6 @@ export default Service({

return await ic.call(self.whoami);
}),

// Return the principal identifier of this canister via the global `ic` object.
// This is much quicker than `id()` above because it isn't making a cross-
// canister call to itself. Additionally, it can now be a `Query` which means it
Expand Down
1 change: 0 additions & 1 deletion examples/notify_raw/canisters/canister2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default Service({
receiveNotification: update([], Void, () => {
notified = true;
}),

getNotified: query([], bool, () => {
return notified;
})
Expand Down
7 changes: 0 additions & 7 deletions examples/null_example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,41 @@ export default Service({
nullFunction: query([Null], Null, (param) => {
return param;
}),

voidIsNotNull: query([], Void, () => {
ic.print(
'Even though they are both None in Python, for Candid null and void are different.'
);
}),

getPartiallyNullRecord: query([], PartiallyNullRecord, () => {
return {
firstItem: 1n,
secondItem: null,
thirdItem: 3n
};
}),

setPartiallyNullRecord: update(
[PartiallyNullRecord],
PartiallyNullRecord,
(param) => {
return param;
}
),

getSmallNullRecord: query([], TwoNullRecord, () => {
return {
firstItem: null,
secondItem: null
};
}),

setSmallNullRecord: update([TwoNullRecord], TwoNullRecord, (param) => {
return param;
}),

getLargeNullRecord: query([], ThreeNullRecord, () => {
return {
firstItem: null,
secondItem: null,
thirdItem: null
};
}),

setLargeNullRecord: update([ThreeNullRecord], ThreeNullRecord, (param) => {
return param;
})
Expand Down
6 changes: 0 additions & 6 deletions examples/optional_types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ export default Service({
head: []
};
}),

getHead: query([], Opt(Head), () => {
return [
{
elements: []
}
];
}),

getHeadWithElements: query([], Opt(Head), () => {
return [
{
Expand All @@ -40,19 +38,15 @@ export default Service({
}
];
}),

getElement: query([Opt(Opt(Element))], Opt(Opt(Element)), (element) => {
return element;
}),

getNull: query([], Null, () => {
return null;
}),

getOptNull: query([], Opt(text), () => {
return [];
}),

stringToBoolean: query([Opt(text)], bool, (optString) => {
if (optString.length > 0) {
return true;
Expand Down
2 changes: 0 additions & 2 deletions examples/outgoing_http_requests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default Service({
cycles: 50_000_000n
});
}),

// TODO the replica logs give some concerning output: https://forum.dfinity.org/t/fix-me-in-http-outcalls-call-raw/19435
xkcdRaw: update(
[],
Expand Down Expand Up @@ -68,7 +67,6 @@ export default Service({
},
{ manual: true }
),

xkcdTransform: query([HttpTransformArgs], HttpResponse, (args) => {
return {
...args.response,
Expand Down
5 changes: 0 additions & 5 deletions examples/rejections/canisters/rejections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,32 @@ export default Service({
Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai')
);
}),

getRejectionCodeNoError: update([], RejectionCode, async () => {
await ic.call(someService.accept);

return ic.rejectCode();
}),

getRejectionCodeDestinationInvalid: update([], RejectionCode, async () => {
try {
await ic.call(nonexistentCanister.method);
} catch (error) {}

return ic.rejectCode();
}),

getRejectionCodeCanisterReject: update([], RejectionCode, async () => {
try {
await ic.call(someService.reject, { args: ['reject'] });
} catch (error) {}

return ic.rejectCode();
}),

getRejectionCodeCanisterError: update([], RejectionCode, async () => {
try {
await ic.call(someService.error);
} catch (error) {}

return ic.rejectCode();
}),

getRejectionMessage: update([text], text, async (message: text) => {
try {
await ic.call(someService.reject, { args: [message] });
Expand Down

0 comments on commit 3022db4

Please sign in to comment.