Skip to content

Commit

Permalink
Replace or with nullish coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tillrohrmann committed Aug 17, 2023
1 parent f9875c7 commit 8cb32b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion typescript/lambda-greeter/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const doGreetAndRemember = async (
ctx: restate.RestateContext,
name: string
) => {
let seen = (await ctx.get<number>("seen")) || 0;
let seen = (await ctx.get<number>("seen")) ?? 0;
seen += 1;

ctx.set("seen", seen);
Expand Down
6 changes: 3 additions & 3 deletions typescript/ticket-reservation/src/ticket_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum TicketStatus {

const doReserveTicket = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Available) {
ctx.set("status", TicketStatus.Reserved);
Expand All @@ -31,7 +31,7 @@ const doReserveTicket = async (ctx: restate.RpcContext) => {

const doUnreserveTicket = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Sold) {
return false;
Expand All @@ -43,7 +43,7 @@ const doUnreserveTicket = async (ctx: restate.RpcContext) => {

const doMarkAsSold = async (ctx: restate.RpcContext) => {
const status =
(await ctx.get<TicketStatus>("status")) || TicketStatus.Available;
(await ctx.get<TicketStatus>("status")) ?? TicketStatus.Available;

if (status === TicketStatus.Reserved) {
ctx.set("status", TicketStatus.Sold);
Expand Down
4 changes: 2 additions & 2 deletions typescript/ticket-reservation/src/user_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const doAddTicket = async (

if (reservation_response) {
// add ticket to user session items
const tickets = (await ctx.get<string[]>("items")) || [];
const tickets = (await ctx.get<string[]>("items")) ?? [];
tickets.push(ticketId);
ctx.set("items", tickets);

Expand All @@ -42,7 +42,7 @@ const doExpireTicket = async (
ticketId: string
) => {
ctx.send(ticketDbApi).unreserve(ticketId);
const tickets = (await ctx.get<string[]>("items")) || [];
const tickets = (await ctx.get<string[]>("items")) ?? [];

const index = tickets.findIndex((id) => id === ticketId);

Expand Down

0 comments on commit 8cb32b6

Please sign in to comment.