matschik / component-party.dev

πŸŽ‰ Web component JS frameworks overview by their syntax and features
https://component-party.dev
MIT License
2.53k stars 224 forks source link

Including Angular >v17 signal syntax examples #241

Open jicruz96 opened 2 months ago

jicruz96 commented 2 months ago

Angular has introduced new signal-based primitives for state management that are likely to become the golden path moving forward, similar to how Svelte is changing their primitives between v4 and v5.

Would project maintainers consider a PR that adds Angular signal syntax examples a welcome contribution? If so, I'd be open to giving it a go.

LcsGa commented 1 month ago

Hi! I just discovered this awesome project and I think the same as you! I was wondering if, like for svelte, we could add another more modern version of how we do things in angular! I was thinking about something like angular-renaissance like they call it. The reason why I propose another folder instead of simply modifying the current one is that, for what I know, a lot of people still use the "older" practices.

LcsGa commented 1 month ago

Also, the reason why I propose a name like "Angular renaissance" (or similar) is because many changes came from v14 (like inject or standalone components), v15 (host directives, the new config file, etc), v16 (signal, computed, effect), and so on!

matschik commented 1 month ago

From a non-Angular developer, Angular Renaissance is confusing. If I understand well, it's Angular using signals feature so I would call it Angular with signals. Component Party could help Angular developers to have a preview how it would be to switch from non-signals to signals.

If you want to contribute, you can maybe check this PR https://github.com/matschik/component-party.dev/pull/234 or submit a new PR.

LcsGa commented 1 month ago

The thing is that it won't only be arround signals but also arround the new control flow, signals, the standalone, the new inject function, new querries, etc like:

@Component({
  standalone: true,
  imports: [Button],
  selector: 'app-root',
  styles: `
    :host {
      display: block;
      padding: 1rem;
    }
  `,
  template: `
    @for (color of colors(); track color) {
      <app-button [color]="color">{{ color }} button</app-button>
    }
  `
})
export class AppComponent {
  readonly colors = signals(['red', 'green']);

  constructor() {
    this.colors.update(colors => [...colors, 'blue']);
  }

  // and so on
}

instead of:

@Component({
  selector: 'app-root',
  styles: [
    `
      :host {
        display: block;
        padding: 1rem;
      }
    `
  ],
  template: `
      <app-button *ngFor="let color of colors; trackBy: trackByColor" [color]="color">{{ color }} button</app-button>
  `
})
export class AppComponent {
  readonly colors = ['red', 'green'];

  constructor() {
    this.colors.push('blue'); // looks simpler but considering the fact that angular is becoming zoneless, it is not + like this the perfs can be badly impacted
  }

  // I add this simply because it is now obligated with the new control flow, that also simplified it
  trackByColor(color: string) {
    return color;
  }

  // and so on
}

@NgModule({
  declarations: [AppComponent],
  imports: [Button, NgFor],
  export: [AppComponent]
})
export class AppModule {}

And there, I missed a lot of other new features that makes Angular easier that it used to be... So Angular signals won't be "enough". If Angular renaissance is confusing (which I understand), maybe could we call it Angular 14+. or other people liked to call it Angular 3, a little bit like when Angular v2 replaced Angular JS, since Angular 3 has never been released (but Google didn't adopt this name). There could be other names like Angular nowadays or similar (but it seems even more confusing :sweat_smile:)

LcsGa commented 1 month ago

About the PR #234 it is a very good basis but can be improved with other new features (like the viewChild signal based query instead of the @ViewChild decorator for example). And the Angular17 name isn't relevant imo. In v18.1 we now have an @let to declare template variable, which is a great addition but if people see this there, in an Angular17 folder, they will be confused as they won't be able to use it in their v17 apps. In v18, we also finaly have default templates for content projection, which is displayed in this project too.

LcsGa commented 1 month ago

And what about Angular renaissance (v14+) ? It's a little verbose but it shows the user that the Renaissance, as the Angular team themselves call it, started with angular 14 and that it is still evolving. Plus it gives a more memorable name (like angular 2 used to be).

matschik commented 1 month ago

Ok let's be clear, what would be responsabilities of these on Component Party:

I think:

What do you think ?

LcsGa commented 1 month ago

I think that's great!

LcsGa commented 1 month ago

I made all the changes (even in the "Angular" files to better show the diff with "Angular Renaissance" but:

component-party.dev@2.0.0 dev /home/lucas/dev/component-party.dev vite

[generateFrameworkContent] Generating framework content files... TypeError: Cannot read properties of undefined (reading 'push') at file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2843:40 at async Promise.all (index 4) at async generateContent (file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2831:7) at async build (file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2981:7) at async PluginContext.buildStart (file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2997:9) at async Promise.all (index 6) at async PluginContainer.hookParallel (file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:49481:5) at async PluginContainer.buildStart (file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:49484:5) at async file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:63425:7 at async httpServer.listen (file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:63440:9) error when starting dev server: TypeError: Cannot read properties of undefined (reading 'push') at file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2843:40 at async Promise.all (index 4) at async generateContent (file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2831:7) at async build (file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2981:7) at async PluginContext.buildStart (file:///home/lucas/dev/component-party.dev/vite.config.js.timestamp-1721509708644-d2f6b8691061.mjs:2997:9) at async Promise.all (index 6) at async PluginContainer.hookParallel (file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:49481:5) at async PluginContainer.buildStart (file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:49484:5) at async file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:63425:7 at async httpServer.listen (file:///home/lucas/dev/component-party.dev/nodemodules/.pnpm/vite@5.3.4@types+node@20.14.11_terser@5.31.3/node_modules/vite/dist/node/chunks/dep-D8YhmIY-.js:63440:9)  ELIFECYCLE  Command failed with exit code 1.

- I can't commit
```sh
git commit -m "feat(angular): update the existing files + add the new angular (renaissance) practices"
βœ” Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ package.json β€” 66 files
    ❯ *.{js,jsx,ts,tsx,vue,gjs} β€” 62 files
      βœ– eslint --cache --fix [FAILED]
    ↓ **/svelte4/*.svelte β€” no files
    ❯ *.{js,jsx,ts,tsx,svelte,vue,html,md,css,hbs} β€” 64 files
      βœ– prettier --cache --write [KILLED]
↓ Skipped because of errors from tasks.
βœ” Reverting to original state because of errors...
βœ” Cleaning up temporary files...

βœ– eslint --cache --fix:

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Cannot read config file: /home/lucas/dev/component-party.dev/.eslintrc.cjs
Error: Function.prototype.apply was called on undefined, which is a undefined and not a function
    at $o (/home/lucas/dev/component-party.dev/node_modules/.pnpm/esm@3.2.25/node_modules/esm/esm.js:1:224377)
    at wu (/home/lucas/dev/component-party.dev/node_modules/.pnpm/esm@3.2.25/node_modules/esm/esm.js:1:227324)
    at Eu (/home/lucas/dev/component-party.dev/node_modules/.pnpm/esm@3.2.25/node_modules/esm/esm.js:1:227999)
    at Module.<anonymous> (/home/lucas/dev/component-party.dev/node_modules/.pnpm/esm@3.2.25/node_modules/esm/esm.js:1:295976)
    at require (/home/lucas/dev/component-party.dev/node_modules/.pnpm/esm@3.2.25/node_modules/esm/esm.js:1:279589)
    at Object.<anonymous> (/home/lucas/dev/component-party.dev/.eslintrc.cjs:2:18)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
(node:28584) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

βœ– prettier --cache --write failed without output (KILLED).
husky - pre-commit script failed (code 1)

I actually have no idea what I did wrong :sweat_smile:

LcsGa commented 1 month ago

If you can and if you want, you can reach me on discord to find what's the issue. My username is lcsga.

matschik commented 1 month ago

I think there is an error on your modifications to frameworks.mjs file. Submit a PR and make it a draft. You can commit using git push --no-verify

LcsGa commented 1 month ago

Okay thanks, I'll do that!

LcsGa commented 1 month ago

Hi @matschik, could you take a look at my draft ?