Discussion
Loading...

#Tag

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
pvergain (framapiaf) boosted
Inautilo
Inautilo
@inautilo@mastodon.social  ·  activity timestamp 6 months ago

#Development #Overviews
When can I use the Temporal API? · Why JavaScript’s Date API replacement took so long https://ilo.im/165c7r

_____
#TC39 #EcmaScript #JavaScript #TemporalAPI #DateAPI #API #Browser #WebDev #Frontend

  • Copy link
  • Flag this post
  • Block
Shini92 :ablobblewobble:
Shini92 :ablobblewobble:
@Shini92@mas.to  ·  activity timestamp 5 months ago

I'm working on a #poc in plain #nodejs 👀
Not published yet, put maybe I will fight #nestjs as a competitor 🤔

This is already working AND fully written in #es2025 #esm with #tc39 decorator proposal

What do you think?

```ts
const cats: Cat[] = [
  new Cat({ id: "1aefd497-bb47-47e3-b160-cb69c5ba0ff4", name: "Kami", age: 4 }),
];

@Path("/cats")
export class CatController {
  @Get
  @Path("/")
  public list(): Cat[] {
    return cats;
  }

  @Get
  @Path("/:id")
  public getById(@PathVariable() id: UUID): Cat | null {
    return cats.find((cat) => cat.id === id) ?? null;
  }

  @Post
  @Path("/")
  public create(@RequestBody(Cat) cat: Cat): Cat {
    cat.id = randomUUID();
    cats.push(cat);
    return cat;
  }

  @Put
  @Path("/:id")
  public update(@PathVariable() id: UUID, @RequestBody(Cat) cat: Cat): Cat {
    const index = cats.findIndex((c) => c.id === id);
    if (index === -1) {
      throw new NotFoundResponseError("Cat not found");
    }
    cats[index] = cat;
    return cat;
  }

  @Delete
  @Path("/:id")
  public delete(@PathVariable() id: UUID): void {
    const index = cats.findIndex((c) => c.id === id);
    if (index === -1) {
      throw new NotFoundResponseError("Cat not found");
    }
    cats.splice(index, 1);
  }
}
```
```ts const cats: Cat[] = [ new Cat({ id: "1aefd497-bb47-47e3-b160-cb69c5ba0ff4", name: "Kami", age: 4 }), ]; @Path("/cats") export class CatController { @Get @Path("/") public list(): Cat[] { return cats; } @Get @Path("/:id") public getById(@PathVariable() id: UUID): Cat | null { return cats.find((cat) => cat.id === id) ?? null; } @Post @Path("/") public create(@RequestBody(Cat) cat: Cat): Cat { cat.id = randomUUID(); cats.push(cat); return cat; } @Put @Path("/:id") public update(@PathVariable() id: UUID, @RequestBody(Cat) cat: Cat): Cat { const index = cats.findIndex((c) => c.id === id); if (index === -1) { throw new NotFoundResponseError("Cat not found"); } cats[index] = cat; return cat; } @Delete @Path("/:id") public delete(@PathVariable() id: UUID): void { const index = cats.findIndex((c) => c.id === id); if (index === -1) { throw new NotFoundResponseError("Cat not found"); } cats.splice(index, 1); } } ```
```ts const cats: Cat[] = [ new Cat({ id: "1aefd497-bb47-47e3-b160-cb69c5ba0ff4", name: "Kami", age: 4 }), ]; @Path("/cats") export class CatController { @Get @Path("/") public list(): Cat[] { return cats; } @Get @Path("/:id") public getById(@PathVariable() id: UUID): Cat | null { return cats.find((cat) => cat.id === id) ?? null; } @Post @Path("/") public create(@RequestBody(Cat) cat: Cat): Cat { cat.id = randomUUID(); cats.push(cat); return cat; } @Put @Path("/:id") public update(@PathVariable() id: UUID, @RequestBody(Cat) cat: Cat): Cat { const index = cats.findIndex((c) => c.id === id); if (index === -1) { throw new NotFoundResponseError("Cat not found"); } cats[index] = cat; return cat; } @Delete @Path("/:id") public delete(@PathVariable() id: UUID): void { const index = cats.findIndex((c) => c.id === id); if (index === -1) { throw new NotFoundResponseError("Cat not found"); } cats.splice(index, 1); } } ```
  • Copy link
  • Flag this post
  • Block
Inautilo
Inautilo
@inautilo@mastodon.social  ·  activity timestamp 6 months ago

#Development #Overviews
When can I use the Temporal API? · Why JavaScript’s Date API replacement took so long https://ilo.im/165c7r

_____
#TC39 #EcmaScript #JavaScript #TemporalAPI #DateAPI #API #Browser #WebDev #Frontend

  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct